Skip to content

Commit 7c855a6

Browse files
authored
fix(core): tabs aria ssr compat (#2863)
1 parent b84507d commit 7c855a6

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

.changeset/ready-garlics-lose.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
"@patternfly/pfe-core": patch
3+
---
4+
`TabsARIAController`: improve SSR compatibility

core/pfe-core/controllers/tabs-aria-controller.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ReactiveController, ReactiveControllerHost } from 'lit';
1+
import { isServer, type ReactiveController, type ReactiveControllerHost } from 'lit';
22

33
import { Logger } from '@patternfly/pfe-core/controllers/logger.js';
44

@@ -19,7 +19,7 @@ export class TabsAriaController<
1919

2020
#host: ReactiveControllerHost;
2121

22-
#element: HTMLElement;
22+
#element!: HTMLElement;
2323

2424
#tabPanelMap = new Map<Tab, Panel>();
2525

@@ -52,6 +52,10 @@ export class TabsAriaController<
5252
) {
5353
this.#options = options;
5454
this.#logger = new Logger(host);
55+
(this.#host = host).addController(this);
56+
if (isServer) {
57+
return;
58+
}
5559
if (host instanceof HTMLElement) {
5660
this.#element = host;
5761
} else {
@@ -63,7 +67,6 @@ export class TabsAriaController<
6367
}
6468
this.#element = element;
6569
}
66-
(this.#host = host).addController(this);
6770
this.#element.addEventListener('slotchange', this.#onSlotchange);
6871
if (this.#element.isConnected) {
6972
this.hostConnected();
@@ -93,7 +96,7 @@ export class TabsAriaController<
9396
this.#tabPanelMap.clear();
9497
const tabs = [];
9598
const panels = [];
96-
for (const child of this.#element.children) {
99+
for (const child of this.#element?.children ?? []) {
97100
if (this.#options.isTab(child)) {
98101
tabs.push(child);
99102
child.role ??= 'tab';

0 commit comments

Comments
 (0)