File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed
Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -248,6 +248,21 @@ class A11yValidator {
248248 }
249249 }
250250
251+ private checkInitialFocusNotCloseButton ( dialogElement : HTMLElement ) : number {
252+ const active = document . activeElement ;
253+ if ( ! active || ! dialogElement . contains ( active ) ) return 0 ;
254+
255+ if ( active . classList . contains ( 'ui-dialog-titlebar-close' ) ) {
256+ console . error (
257+ new A11yValidatorException (
258+ `In '${ this . getDialogTitle ( active as HTMLElement ) } ': initial keyboard focus is on the close (X) button in the titlebar. Focus should be on a control inside the dialog body.` ,
259+ ) ,
260+ ) ;
261+ return 1 ;
262+ }
263+ return 0 ;
264+ }
265+
251266 private checkDuplicateButtonLabels ( container : HTMLElement ) : number {
252267 const buttons = container . querySelectorAll ( 'button[aria-labelledby]' ) ;
253268 const labelMap = new Map < string , HTMLElement [ ] > ( ) ;
@@ -363,10 +378,11 @@ class A11yValidator {
363378 validateDialog ( dialogElement : HTMLElement ) : void {
364379 const content = dialogElement . querySelector ( '.ui-dialog-content' ) ;
365380
366- const errorCount = this . validateContainer (
367- dialogElement ,
368- content instanceof HTMLElement ? content : undefined ,
369- ) ;
381+ const errorCount =
382+ this . validateContainer (
383+ dialogElement ,
384+ content instanceof HTMLElement ? content : undefined ,
385+ ) + this . checkInitialFocusNotCloseButton ( dialogElement ) ;
370386
371387 if ( errorCount === 0 ) {
372388 console . error ( 'A11yValidator: dialog passed all checks' ) ;
You can’t perform that action at this time.
0 commit comments