Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(inline-editable): fix rendering tied to default slot content #10456

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its kind of odd to be setting scale based on a slotted element's scale.

To handle this better, an internal event for scale change would be needed.

IMO we should just remove this. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this is that if inputElements scale changes after being slotted, this wouldn't get picked up.
If inputElement is replaced after initialization then the scale is already set at that point too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Can you create an issue for this?

@geospatialem @brittneytewks We can plan for removal in a breaking change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};

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

private get shouldShowControls(): boolean {
Expand Down
Loading