Skip to content

Commit

Permalink
fix(core): tabs aria ssr compat (#2863)
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers authored Oct 9, 2024
1 parent b84507d commit 7c855a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .changeset/ready-garlics-lose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@patternfly/pfe-core": patch
---
`TabsARIAController`: improve SSR compatibility
11 changes: 7 additions & 4 deletions core/pfe-core/controllers/tabs-aria-controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ReactiveController, ReactiveControllerHost } from 'lit';
import { isServer, type ReactiveController, type ReactiveControllerHost } from 'lit';

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

Expand All @@ -19,7 +19,7 @@ export class TabsAriaController<

#host: ReactiveControllerHost;

#element: HTMLElement;
#element!: HTMLElement;

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

Expand Down Expand Up @@ -52,6 +52,10 @@ export class TabsAriaController<
) {
this.#options = options;
this.#logger = new Logger(host);
(this.#host = host).addController(this);
if (isServer) {
return;
}
if (host instanceof HTMLElement) {
this.#element = host;
} else {
Expand All @@ -63,7 +67,6 @@ export class TabsAriaController<
}
this.#element = element;
}
(this.#host = host).addController(this);
this.#element.addEventListener('slotchange', this.#onSlotchange);
if (this.#element.isConnected) {
this.hostConnected();
Expand Down Expand Up @@ -93,7 +96,7 @@ export class TabsAriaController<
this.#tabPanelMap.clear();
const tabs = [];
const panels = [];
for (const child of this.#element.children) {
for (const child of this.#element?.children ?? []) {
if (this.#options.isTab(child)) {
tabs.push(child);
child.role ??= 'tab';
Expand Down

0 comments on commit 7c855a6

Please sign in to comment.