Skip to content

Commit

Permalink
fix(inline-editable): fix rendering tied to default slot content (#10456
Browse files Browse the repository at this point in the history
)

**Related Issue:** #6059

## Summary

- remove use of `getSlotted` utility
- replace with `slotchange` event 
- existing tests should suffice
  • Loading branch information
driskull authored and benelan committed Feb 8, 2025
1 parent 6ed32c6 commit 50ede48
Showing 1 changed file with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
VNode,
Watch,
} from "@stencil/core";
import { getSlotted } from "../../utils/dom";
import {
InteractiveComponent,
InteractiveContainer,
Expand All @@ -25,7 +24,6 @@ import {
setUpLoadableComponent,
} from "../../utils/loadable";
import { connectLocalized, disconnectLocalized, LocalizedComponent } from "../../utils/locale";
import { createObserver } from "../../utils/observers";
import {
connectMessages,
disconnectMessages,
Expand All @@ -34,6 +32,7 @@ import {
updateMessages,
} from "../../utils/t9n";
import { Scale } from "../interfaces";
import { slotChangeGetAssignedElements } from "../../utils/dom";
import { InlineEditableMessages } from "./assets/inline-editable/t9n";
import { CSS } from "./resources";

Expand Down Expand Up @@ -130,8 +129,6 @@ export class InlineEditable
connectLabel(this);
connectLocalized(this);
connectMessages(this);
this.mutationObserver?.observe(this.el, { childList: true });
this.mutationObserverCallback();
}

async componentWillLoad(): Promise<void> {
Expand All @@ -147,7 +144,6 @@ export class InlineEditable
disconnectLabel(this);
disconnectLocalized(this);
disconnectMessages(this);
this.mutationObserver?.disconnect();
}

componentDidRender(): void {
Expand All @@ -163,7 +159,7 @@ export class InlineEditable
onKeyDown={this.escapeKeyHandler}
>
<div class={CSS.inputWrapper}>
<slot />
<slot onSlotchange={this.handleDefaultSlotChange} />
</div>
<div class={CSS.controlsWrapper}>
<calcite-button
Expand Down Expand Up @@ -274,8 +270,6 @@ export class InlineEditable

labelEl: HTMLCalciteLabelElement;

mutationObserver = createObserver("mutation", () => this.mutationObserverCallback());

@State() defaultMessages: InlineEditableMessages;

@State() effectiveLocale: string;
Expand Down Expand Up @@ -305,28 +299,24 @@ export class InlineEditable
//
//--------------------------------------------------------------------------

mutationObserverCallback(): void {
this.updateSlottedInput();
this.scale = this.scale || this.inputElement?.scale;
}

onLabelClick(): void {
this.setFocus();
}

updateSlottedInput(): void {
const inputElement: HTMLCalciteInputElement = getSlotted(this.el, {
matches: "calcite-input",
});
handleDefaultSlotChange = (event: Event): void => {
const inputElement = slotChangeGetAssignedElements(event).filter(
(el): el is HTMLCalciteInputElement => el.matches("calcite-input"),
)[0];

this.inputElement = inputElement;

if (!inputElement) {
return;
}

this.inputElement.disabled = this.disabled;
this.inputElement.label = this.inputElement.label || getLabelText(this);
inputElement.disabled = this.disabled;
inputElement.label = inputElement.label || getLabelText(this);
this.scale = this.scale || this.inputElement?.scale;
};

onLabelClick(): void {
this.setFocus();
}

private get shouldShowControls(): boolean {
Expand Down

0 comments on commit 50ede48

Please sign in to comment.