Skip to content

Commit b10dfc4

Browse files
driskullbenelan
authored andcommitted
fix(combobox-item): fix rendering tied to named-slot content (#10450)
**Related Issue:** #6059 ## Summary - remove use of `getSlotted` utility - replace with `slotchange` event and `@State` variables to update the display of elements. - existing tests should suffice
1 parent deab4fe commit b10dfc4

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

packages/calcite-components/src/components/combobox-item/combobox-item.tsx

+14-21
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@ import {
66
h,
77
Host,
88
Prop,
9+
State,
910
VNode,
1011
Watch,
1112
} from "@stencil/core";
12-
import {
13-
ConditionalSlotComponent,
14-
connectConditionalSlotComponent,
15-
disconnectConditionalSlotComponent,
16-
} from "../../utils/conditionalSlot";
17-
import { getSlotted } from "../../utils/dom";
1813
import { guid } from "../../utils/guid";
1914
import {
2015
InteractiveComponent,
@@ -26,6 +21,7 @@ import { getAncestors, getDepth, isSingleLike } from "../combobox/utils";
2621
import { Scale, SelectionMode } from "../interfaces";
2722
import { getIconScale } from "../../utils/component";
2823
import { IconNameOrString } from "../icon/interfaces";
24+
import { slotChangeHasContent } from "../../utils/dom";
2925
import { CSS, SLOTS } from "./resources";
3026

3127
/**
@@ -37,7 +33,7 @@ import { CSS, SLOTS } from "./resources";
3733
styleUrl: "combobox-item.scss",
3834
shadow: true,
3935
})
40-
export class ComboboxItem implements ConditionalSlotComponent, InteractiveComponent {
36+
export class ComboboxItem implements InteractiveComponent {
4137
// --------------------------------------------------------------------------
4238
//
4339
// Properties
@@ -158,6 +154,8 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon
158154

159155
@Element() el: HTMLCalciteComboboxItemElement;
160156

157+
@State() hasContent = false;
158+
161159
// --------------------------------------------------------------------------
162160
//
163161
// Lifecycle
@@ -166,11 +164,6 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon
166164

167165
connectedCallback(): void {
168166
this.ancestors = getAncestors(this.el);
169-
connectConditionalSlotComponent(this);
170-
}
171-
172-
disconnectedCallback(): void {
173-
disconnectConditionalSlotComponent(this);
174167
}
175168

176169
componentDidRender(): void {
@@ -202,6 +195,10 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon
202195
//
203196
// --------------------------------------------------------------------------
204197

198+
private handleDefaultSlotChange = (event: Event): void => {
199+
this.hasContent = slotChangeHasContent(event);
200+
};
201+
205202
toggleSelected(): Promise<void> {
206203
const isSinglePersistSelect = this.selectionMode === "single-persist";
207204

@@ -262,15 +259,11 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon
262259
}
263260

264261
renderChildren(): VNode {
265-
if (getSlotted(this.el)) {
266-
return (
267-
<ul key="default-slot-container">
268-
<slot />
269-
</ul>
270-
);
271-
}
272-
273-
return null;
262+
return (
263+
<ul hidden={!this.hasContent} key="default-slot-container">
264+
<slot onSlotchange={this.handleDefaultSlotChange} />
265+
</ul>
266+
);
274267
}
275268

276269
render(): VNode {

0 commit comments

Comments
 (0)