Skip to content

Commit cef2dd4

Browse files
committed
chore: change type annotation by keeping treewalker explicitly optional null
1 parent 1482bff commit cef2dd4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

dialog/internal/dialog.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class Dialog extends dialogBaseClass {
152152
// focusable elements. TreeWalker is faster than `querySelectorAll('*')`.
153153
// We check for isServer because there isn't a "document" during an SSR
154154
// run.
155-
private readonly treewalker = isServer ? {} as TreeWalker : document.createTreeWalker(
155+
private readonly treewalker = isServer ? null : document.createTreeWalker(
156156
this,
157157
NodeFilter.SHOW_ELEMENT,
158158
);
@@ -561,7 +561,12 @@ export class Dialog extends dialogBaseClass {
561561
// won't actually reach here.
562562
}
563563

564-
private getFirstAndLastFocusableChildren() {
564+
private getFirstAndLastFocusableChildren(): [HTMLElement, HTMLElement]
565+
| [null, null] {
566+
if (!this.treewalker) {
567+
return [null, null] as const;
568+
}
569+
565570
let firstFocusableChild: HTMLElement | null = null;
566571
let lastFocusableChild: HTMLElement | null = null;
567572

@@ -584,9 +589,7 @@ export class Dialog extends dialogBaseClass {
584589
// We set lastFocusableChild immediately after finding a
585590
// firstFocusableChild, which means the pair is either both null or both
586591
// non-null. Cast since TypeScript does not recognize this.
587-
return [firstFocusableChild, lastFocusableChild] as
588-
| [HTMLElement, HTMLElement]
589-
| [null, null];
592+
return [firstFocusableChild, lastFocusableChild];
590593
}
591594
}
592595

0 commit comments

Comments
 (0)