@@ -152,7 +152,7 @@ export class Dialog extends dialogBaseClass {
152
152
// focusable elements. TreeWalker is faster than `querySelectorAll('*')`.
153
153
// We check for isServer because there isn't a "document" during an SSR
154
154
// run.
155
- private readonly treewalker = isServer ? { } as TreeWalker : document . createTreeWalker (
155
+ private readonly treewalker = isServer ? null : document . createTreeWalker (
156
156
this ,
157
157
NodeFilter . SHOW_ELEMENT ,
158
158
) ;
@@ -561,7 +561,12 @@ export class Dialog extends dialogBaseClass {
561
561
// won't actually reach here.
562
562
}
563
563
564
- private getFirstAndLastFocusableChildren ( ) {
564
+ private getFirstAndLastFocusableChildren ( ) : [ HTMLElement , HTMLElement ]
565
+ | [ null , null ] {
566
+ if ( ! this . treewalker ) {
567
+ return [ null , null ] as const ;
568
+ }
569
+
565
570
let firstFocusableChild : HTMLElement | null = null ;
566
571
let lastFocusableChild : HTMLElement | null = null ;
567
572
@@ -584,9 +589,7 @@ export class Dialog extends dialogBaseClass {
584
589
// We set lastFocusableChild immediately after finding a
585
590
// firstFocusableChild, which means the pair is either both null or both
586
591
// non-null. Cast since TypeScript does not recognize this.
587
- return [ firstFocusableChild , lastFocusableChild ] as
588
- | [ HTMLElement , HTMLElement ]
589
- | [ null , null ] ;
592
+ return [ firstFocusableChild , lastFocusableChild ] ;
590
593
}
591
594
}
592
595
0 commit comments