File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 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 {
102102 '[attr.autocomplete]' : 'autocompleteAttribute' ,
103103 '[attr.role]' : 'autocompleteDisabled ? null : "combobox"' ,
104104 '[attr.aria-autocomplete]' : 'autocompleteDisabled ? null : "list"' ,
105- '[attr.aria-activedescendant]' : 'activeOption? .id' ,
105+ '[attr.aria-activedescendant]' : '(panelOpen && activeOption) ? activeOption .id : null ' ,
106106 '[attr.aria-expanded]' : 'autocompleteDisabled ? null : panelOpen.toString()' ,
107107 '[attr.aria-owns]' : '(autocompleteDisabled || !panelOpen) ? null : autocomplete?.id' ,
108108 // 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', () => {
16441644 . toContain ( 'mat-active' , 'Expected first option to be highlighted.' ) ;
16451645 } ) ) ;
16461646
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+
16471670 it ( 'should be able to configure preselecting the first option globally' , fakeAsync ( ( ) => {
16481671 overlayContainer . ngOnDestroy ( ) ;
16491672 fixture . destroy ( ) ;
You can’t perform that action at this time.
0 commit comments