File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ function keyboardBindings(event: KeyboardEvent) {
34
34
}
35
35
break
36
36
case 'Escape' :
37
- clearSelection ( list )
37
+ clearSelection ( input , list )
38
38
break
39
39
case 'ArrowDown' :
40
40
navigate ( input , list , 1 )
@@ -109,7 +109,8 @@ export function navigate(
109
109
}
110
110
}
111
111
112
- function clearSelection ( list ) : void {
112
+ export function clearSelection ( input : HTMLTextAreaElement | HTMLInputElement , list : HTMLElement ) : void {
113
+ input . removeAttribute ( 'aria - activedescendant ')
113
114
const target = list . querySelector ( '[aria-selected="true"]' )
114
115
if ( ! target ) return
115
116
target . setAttribute ( 'aria-selected' , 'false' )
@@ -123,5 +124,5 @@ function trackComposition(event: Event): void {
123
124
const list = document . getElementById ( input . getAttribute ( 'aria-owns' ) || '' )
124
125
if ( ! list ) return
125
126
126
- clearSelection ( list )
127
+ clearSelection ( input , list )
127
128
}
Original file line number Diff line number Diff line change 3
3
declare export function install(input: HTMLTextAreaElement | HTMLInputElement, list: HTMLElement): void;
4
4
declare export function navigate(input: HTMLTextAreaElement | HTMLInputElement, list: HTMLElement, indexDiff?: -1 | 1): void;
5
5
declare export function uninstall(input: HTMLTextAreaElement | HTMLInputElement, list: HTMLElement): void;
6
+ declare export function clearSelection(input: HTMLTextAreaElement | HTMLInputElement, list: HTMLElement): void;
Original file line number Diff line number Diff line change @@ -132,5 +132,20 @@ describe('combobox-nav', function() {
132
132
assert ( eventFired )
133
133
assert . equal ( window . location . hash , '#wall-e' )
134
134
} )
135
+
136
+ it ( 'clears aria-activedescendant and sets aria-selected=false when cleared' , function ( ) {
137
+ const input = document . querySelector ( 'input' )
138
+ const list = document . querySelector ( 'ul' )
139
+ const options = document . querySelectorAll ( 'li' )
140
+
141
+ press ( input , 'ArrowDown' )
142
+ assert . equal ( options [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
143
+ assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'baymax' )
144
+
145
+ comboboxNav . clearSelection ( input , list )
146
+
147
+ assert . equal ( options [ 0 ] . getAttribute ( 'aria-selected' ) , 'false' )
148
+ assert . equal ( input . hasAttribute ( 'aria-activedescendant' ) , false )
149
+ } )
135
150
} )
136
151
} )
You can’t perform that action at this time.
0 commit comments