File tree 2 files changed +24
-1
lines changed
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ export function getMatAutocompleteMissingPanelError(): Error {
102
102
'[attr.autocomplete]' : 'autocompleteAttribute' ,
103
103
'[attr.role]' : 'autocompleteDisabled ? null : "combobox"' ,
104
104
'[attr.aria-autocomplete]' : 'autocompleteDisabled ? null : "list"' ,
105
- '[attr.aria-activedescendant]' : 'activeOption? .id' ,
105
+ '[attr.aria-activedescendant]' : '(panelOpen && activeOption) ? activeOption .id : null ' ,
106
106
'[attr.aria-expanded]' : 'autocompleteDisabled ? null : panelOpen.toString()' ,
107
107
'[attr.aria-owns]' : '(autocompleteDisabled || !panelOpen) ? null : autocomplete?.id' ,
108
108
// Note: we use `focusin`, as opposed to `focus`, in order to open the panel
Original file line number Diff line number Diff line change @@ -1644,6 +1644,29 @@ describe('MatAutocomplete', () => {
1644
1644
. toContain ( 'mat-active' , 'Expected first option to be highlighted.' ) ;
1645
1645
} ) ) ;
1646
1646
1647
+ it ( 'should remove aria-activedescendant when panel is closed with autoActiveFirstOption' ,
1648
+ fakeAsync ( ( ) => {
1649
+ const input : HTMLElement = fixture . nativeElement . querySelector ( 'input' ) ;
1650
+
1651
+ expect ( input . hasAttribute ( 'aria-activedescendant' ) )
1652
+ . toBe ( false , 'Expected no active descendant on init.' ) ;
1653
+
1654
+ fixture . componentInstance . trigger . autocomplete . autoActiveFirstOption = true ;
1655
+ fixture . componentInstance . trigger . openPanel ( ) ;
1656
+ fixture . detectChanges ( ) ;
1657
+ zone . simulateZoneExit ( ) ;
1658
+ fixture . detectChanges ( ) ;
1659
+
1660
+ expect ( input . getAttribute ( 'aria-activedescendant' ) )
1661
+ . toBeTruthy ( 'Expected active descendant while open.' ) ;
1662
+
1663
+ fixture . componentInstance . trigger . closePanel ( ) ;
1664
+ fixture . detectChanges ( ) ;
1665
+
1666
+ expect ( input . hasAttribute ( 'aria-activedescendant' ) )
1667
+ . toBe ( false , 'Expected no active descendant when closed.' ) ;
1668
+ } ) ) ;
1669
+
1647
1670
it ( 'should be able to configure preselecting the first option globally' , fakeAsync ( ( ) => {
1648
1671
overlayContainer . ngOnDestroy ( ) ;
1649
1672
fixture . destroy ( ) ;
You can’t perform that action at this time.
0 commit comments