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 @@ -283,6 +283,21 @@ class A11yValidator {
283283 ) ;
284284 }
285285
286+ private checkInitialFocusNotCloseButton ( dialogElement : HTMLElement ) : number {
287+ const active = document . activeElement ;
288+ if ( ! active || ! dialogElement . contains ( active ) ) return 0 ;
289+
290+ if ( active . classList . contains ( 'ui-dialog-titlebar-close' ) ) {
291+ console . error (
292+ new A11yValidatorException (
293+ `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.` ,
294+ ) ,
295+ ) ;
296+ return 1 ;
297+ }
298+ return 0 ;
299+ }
300+
286301 private checkDuplicateButtonLabels ( container : HTMLElement ) : number {
287302 const buttons = container . querySelectorAll ( 'button[aria-labelledby]' ) ;
288303 const labelMap = new Map < string , HTMLElement [ ] > ( ) ;
@@ -398,10 +413,11 @@ class A11yValidator {
398413 validateDialog ( dialogElement : HTMLElement ) : void {
399414 const content = dialogElement . querySelector ( '.ui-dialog-content' ) ;
400415
401- const errorCount = this . validateContainer (
402- dialogElement ,
403- content instanceof HTMLElement ? content : undefined ,
404- ) ;
416+ const errorCount =
417+ this . validateContainer (
418+ dialogElement ,
419+ content instanceof HTMLElement ? content : undefined ,
420+ ) + this . checkInitialFocusNotCloseButton ( dialogElement ) ;
405421
406422 if ( errorCount === 0 ) {
407423 console . error ( 'A11yValidator: dialog passed all checks' ) ;
You can’t perform that action at this time.
0 commit comments