File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
src/material/autocomplete Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -263,6 +263,11 @@ export abstract class _MatAutocompleteTriggerBase
263
263
openPanel ( ) : void {
264
264
this . _attachOverlay ( ) ;
265
265
this . _floatLabel ( ) ;
266
+ // Add aria-owns attribute when the autocomplete becomes visible.
267
+ if ( this . _trackedModal ) {
268
+ const panelId = this . autocomplete . id ;
269
+ addAriaReferencedId ( this . _trackedModal , 'aria-owns' , panelId ) ;
270
+ }
266
271
}
267
272
268
273
/** Closes the autocomplete suggestion panel. */
@@ -302,6 +307,12 @@ export abstract class _MatAutocompleteTriggerBase
302
307
// user clicks outside.
303
308
this . _changeDetectorRef . detectChanges ( ) ;
304
309
}
310
+
311
+ // Remove aria-owns attribute when the autocomplete is no longer visible.
312
+ if ( this . _trackedModal ) {
313
+ const panelId = this . autocomplete . id ;
314
+ removeAriaReferencedId ( this . _trackedModal , 'aria-owns' , panelId ) ;
315
+ }
305
316
}
306
317
307
318
/**
Original file line number Diff line number Diff line change @@ -3729,6 +3729,31 @@ describe('MDC-based MatAutocomplete', () => {
3729
3729
. withContext ( 'expecting modal to own the autocommplete panel' )
3730
3730
. toContain ( panelId ) ;
3731
3731
} ) ) ;
3732
+
3733
+ it ( 'should remove the aria-owns attribute of the modal when the autocomplete panel closes' , fakeAsync ( ( ) => {
3734
+ fixture . componentInstance . trigger . openPanel ( ) ;
3735
+ fixture . componentInstance . trigger . closePanel ( ) ;
3736
+ fixture . detectChanges ( ) ;
3737
+
3738
+ const panelId = fixture . componentInstance . autocomplete . id ;
3739
+ const modalElement = fixture . componentInstance . modal . nativeElement ;
3740
+
3741
+ expect ( modalElement . getAttribute ( 'aria-owns' ) ) . toBeFalsy ( ) ;
3742
+ } ) ) ;
3743
+
3744
+ it ( 'should readd the aria-owns attribute of the modal when the autocomplete panel opens again' , fakeAsync ( ( ) => {
3745
+ fixture . componentInstance . trigger . openPanel ( ) ;
3746
+ fixture . componentInstance . trigger . closePanel ( ) ;
3747
+ fixture . componentInstance . trigger . openPanel ( ) ;
3748
+ fixture . detectChanges ( ) ;
3749
+
3750
+ const panelId = fixture . componentInstance . autocomplete . id ;
3751
+ const modalElement = fixture . componentInstance . modal . nativeElement ;
3752
+
3753
+ expect ( modalElement . getAttribute ( 'aria-owns' ) ?. split ( ' ' ) )
3754
+ . withContext ( 'expecting modal to own the autocommplete panel' )
3755
+ . toContain ( panelId ) ;
3756
+ } ) ) ;
3732
3757
} ) ;
3733
3758
} ) ;
3734
3759
You can’t perform that action at this time.
0 commit comments