@@ -23,6 +23,7 @@ import {of as observableOf, Observable, Subject, defer} from 'rxjs';
23
23
import { DialogRef } from './dialog-ref' ;
24
24
import { DialogConfig } from './dialog-config' ;
25
25
import { Directionality } from '@angular/cdk/bidi' ;
26
+ import { _supportsInert } from '@angular/cdk/platform' ;
26
27
import {
27
28
ComponentType ,
28
29
Overlay ,
@@ -44,8 +45,9 @@ export class Dialog implements OnDestroy {
44
45
private _openDialogsAtThisLevel : DialogRef < any , any > [ ] = [ ] ;
45
46
private readonly _afterAllClosedAtThisLevel = new Subject < void > ( ) ;
46
47
private readonly _afterOpenedAtThisLevel = new Subject < DialogRef > ( ) ;
47
- private _ariaHiddenElements = new Map < Element , string | null > ( ) ;
48
+ private _inertElements = new Map < Element , string | null > ( ) ;
48
49
private _scrollStrategy : ( ) => ScrollStrategy ;
50
+ private _inertAttribute = _supportsInert ( ) ? 'inert' : 'aria-hidden' ;
49
51
50
52
/** Keeps track of the currently-open dialogs. */
51
53
get openDialogs ( ) : readonly DialogRef < any , any > [ ] {
@@ -162,7 +164,7 @@ export class Dialog implements OnDestroy {
162
164
ngOnDestroy ( ) {
163
165
// Make one pass over all the dialogs that need to be untracked, but should not be closed. We
164
166
// want to stop tracking the open dialog even if it hasn't been closed, because the tracking
165
- // determines when `aria-hidden ` is removed from elements outside the dialog.
167
+ // determines when `inert ` is removed from elements outside the dialog.
166
168
reverseForEach ( this . _openDialogsAtThisLevel , dialog => {
167
169
// Check for `false` specifically since we want `undefined` to be interpreted as `true`.
168
170
if ( dialog . config . closeOnDestroy === false ) {
@@ -350,18 +352,18 @@ export class Dialog implements OnDestroy {
350
352
if ( index > - 1 ) {
351
353
( this . openDialogs as DialogRef < R , C > [ ] ) . splice ( index , 1 ) ;
352
354
353
- // If all the dialogs were closed, remove/restore the `aria-hidden`
355
+ // If all the dialogs were closed, remove/restore the inert attribute
354
356
// to a the siblings and emit to the `afterAllClosed` stream.
355
357
if ( ! this . openDialogs . length ) {
356
- this . _ariaHiddenElements . forEach ( ( previousValue , element ) => {
358
+ this . _inertElements . forEach ( ( previousValue , element ) => {
357
359
if ( previousValue ) {
358
- element . setAttribute ( 'aria-hidden' , previousValue ) ;
360
+ element . setAttribute ( this . _inertAttribute , previousValue ) ;
359
361
} else {
360
- element . removeAttribute ( 'aria-hidden' ) ;
362
+ element . removeAttribute ( this . _inertAttribute ) ;
361
363
}
362
364
} ) ;
363
365
364
- this . _ariaHiddenElements . clear ( ) ;
366
+ this . _inertElements . clear ( ) ;
365
367
366
368
if ( emitEvent ) {
367
369
this . _getAfterAllClosed ( ) . next ( ) ;
@@ -387,8 +389,8 @@ export class Dialog implements OnDestroy {
387
389
sibling . nodeName !== 'STYLE' &&
388
390
! sibling . hasAttribute ( 'aria-live' )
389
391
) {
390
- this . _ariaHiddenElements . set ( sibling , sibling . getAttribute ( 'aria-hidden' ) ) ;
391
- sibling . setAttribute ( 'aria-hidden' , 'true' ) ;
392
+ this . _inertElements . set ( sibling , sibling . getAttribute ( this . _inertAttribute ) ) ;
393
+ sibling . setAttribute ( this . _inertAttribute , 'true' ) ;
392
394
}
393
395
}
394
396
}
0 commit comments