Skip to content

fix(combobox-item): fix rendering tied to named-slot content #10450

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

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Changes from 1 commit
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 @@ -6,15 +6,10 @@ import {
h,
Host,
Prop,
State,
VNode,
Watch,
} from "@stencil/core";
import {
ConditionalSlotComponent,
connectConditionalSlotComponent,
disconnectConditionalSlotComponent,
} from "../../utils/conditionalSlot";
import { getSlotted } from "../../utils/dom";
import { guid } from "../../utils/guid";
import {
InteractiveComponent,
Expand All @@ -26,6 +21,7 @@ import { getAncestors, getDepth, isSingleLike } from "../combobox/utils";
import { Scale, SelectionMode } from "../interfaces";
import { getIconScale } from "../../utils/component";
import { IconNameOrString } from "../icon/interfaces";
import { slotChangeHasContent } from "../../utils/dom";
import { CSS, SLOTS } from "./resources";

/**
Expand All @@ -37,7 +33,7 @@ import { CSS, SLOTS } from "./resources";
styleUrl: "combobox-item.scss",
shadow: true,
})
export class ComboboxItem implements ConditionalSlotComponent, InteractiveComponent {
export class ComboboxItem implements InteractiveComponent {
// --------------------------------------------------------------------------
//
// Properties
Expand Down Expand Up @@ -158,19 +154,17 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon

@Element() el: HTMLCalciteComboboxItemElement;

@State() hasContent = false;

// --------------------------------------------------------------------------
//
// Lifecycle
//
// --------------------------------------------------------------------------

connectedCallback(): void {
// todo: refactor: if grandparent is removed, this will not update
this.ancestors = getAncestors(this.el);
Copy link
Member Author

@driskull driskull Sep 30, 2024

Choose a reason for hiding this comment

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

if grandparent is removed, I think this would get stale and incorrect. I don't think it would update because connectedCallback of a grandparent wouldn't trigger anything here.

Do we want to open an issue for this?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we should revisit this. Can you create an issue to refactor this logic and possibly move it up to combobox?

Copy link
Member Author

Choose a reason for hiding this comment

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

created #10459

connectConditionalSlotComponent(this);
}

disconnectedCallback(): void {
disconnectConditionalSlotComponent(this);
}

componentDidRender(): void {
Expand Down Expand Up @@ -202,6 +196,10 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon
//
// --------------------------------------------------------------------------

private handleDefaultSlotChange = (event: Event): void => {
this.hasContent = slotChangeHasContent(event);
};

toggleSelected(): Promise<void> {
const isSinglePersistSelect = this.selectionMode === "single-persist";

Expand Down Expand Up @@ -262,15 +260,11 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon
}

renderChildren(): VNode {
if (getSlotted(this.el)) {
return (
<ul key="default-slot-container">
<slot />
</ul>
);
}

return null;
return (
<ul hidden={!this.hasContent} key="default-slot-container">
<slot onSlotchange={this.handleDefaultSlotChange} />
</ul>
);
}

render(): VNode {
Expand Down
Loading