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 @@ -278,6 +278,11 @@ export class MatAutocompleteTrigger
278
278
openPanel ( ) : void {
279
279
this . _attachOverlay ( ) ;
280
280
this . _floatLabel ( ) ;
281
+ // Add aria-owns attribute when the autocomplete becomes visible.
282
+ if ( this . _trackedModal ) {
283
+ const panelId = this . autocomplete . id ;
284
+ addAriaReferencedId ( this . _trackedModal , 'aria-owns' , panelId ) ;
285
+ }
281
286
}
282
287
283
288
/** Closes the autocomplete suggestion panel. */
@@ -317,6 +322,12 @@ export class MatAutocompleteTrigger
317
322
// user clicks outside.
318
323
this . _changeDetectorRef . detectChanges ( ) ;
319
324
}
325
+
326
+ // Remove aria-owns attribute when the autocomplete is no longer visible.
327
+ if ( this . _trackedModal ) {
328
+ const panelId = this . autocomplete . id ;
329
+ removeAriaReferencedId ( this . _trackedModal , 'aria-owns' , panelId ) ;
330
+ }
320
331
}
321
332
322
333
/**
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