Skip to content

Commit fb079ed

Browse files
author
Sara Dahan
committed
fix(label-group): guard DOM access for SSR
1 parent 9f82c0b commit fb079ed

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

elements/pf-label-group/pf-label-group.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,19 @@ export class PfLabelGroup extends LitElement {
103103

104104
@query('#close-button') private _button?: HTMLButtonElement;
105105

106-
@queryAssignedNodes({
107-
slot: 'category',
108-
flatten: true,
109-
})
110-
private _categorySlotted?: HTMLElement[];
106+
private get _categorySlotted(): HTMLElement[] {
107+
const isServer = typeof window === 'undefined' || !('document' in globalThis);
108+
if (isServer) {
109+
return [];
110+
}
111+
112+
const slot = this.shadowRoot?.querySelector<HTMLSlotElement>('slot[name="category"]');
113+
if (!slot) {
114+
return [];
115+
}
116+
117+
return slot.assignedElements({ flatten: true }) as HTMLElement[];
118+
}
111119

112120
get #labels(): NodeListOf<PfLabel> | PfLabel[] {
113121
if (isServer) {
@@ -207,7 +215,7 @@ export class PfLabelGroup extends LitElement {
207215
this.open = !this.open;
208216
await this.updateComplete;
209217
this.labelsChanged();
210-
const overflow = this.renderRoot.querySelector('#overflow') as PfLabel | null;
218+
const overflow = isServer ? null : this.renderRoot.querySelector('#overflow') as PfLabel | null;
211219
if (overflow) {
212220
this.#tabindex.atFocusedItemIndex = this.#tabindex.items.indexOf(overflow);
213221
}

0 commit comments

Comments
 (0)