@@ -12,6 +12,7 @@ var KEY_DOWN = 40;
12
12
var cache = [ ] ;
13
13
var doc = document ;
14
14
var docElement = doc . documentElement ;
15
+ var c = 0 ;
15
16
16
17
function find ( el ) {
17
18
var entry ;
@@ -51,6 +52,7 @@ function horsey (el, options) {
51
52
var anyInput ;
52
53
var ranchorleft ;
53
54
var ranchorright ;
55
+ var id = 'sey-list-' + c ++ ;
54
56
55
57
if ( o . autoHideOnBlur === void 0 ) { o . autoHideOnBlur = true ; }
56
58
if ( o . autoHideOnClick === void 0 ) { o . autoHideOnClick = true ; }
@@ -90,6 +92,11 @@ function horsey (el, options) {
90
92
cache . push ( entry ) ;
91
93
parent . appendChild ( ul ) ;
92
94
el . setAttribute ( 'autocomplete' , 'off' ) ;
95
+ el . setAttribute ( 'role' , 'combobox' ) ;
96
+ el . setAttribute ( 'aria-owns' , id ) ;
97
+ el . setAttribute ( 'aria-autocomplete' , 'list' ) ;
98
+ ul . setAttribute ( 'id' , id ) ;
99
+ ul . setAttribute ( 'role' , 'listbox' ) ;
93
100
94
101
if ( Array . isArray ( suggestions ) ) {
95
102
loaded ( suggestions ) ;
@@ -125,12 +132,15 @@ function horsey (el, options) {
125
132
}
126
133
}
127
134
128
- function add ( suggestion ) {
135
+ function add ( suggestion , i ) {
129
136
var li = tag ( 'li' , 'sey-item' ) ;
137
+ var suggestionId = id + '-' + i ;
130
138
render ( li , suggestion ) ;
131
139
crossvent . add ( li , 'click' , clickedSuggestion ) ;
132
140
crossvent . add ( li , 'horsey-filter' , filterItem ) ;
133
141
crossvent . add ( li , 'horsey-hide' , hideItem ) ;
142
+ li . setAttribute ( 'role' , 'option' ) ;
143
+ li . setAttribute ( 'id' , suggestionId ) ;
134
144
ul . appendChild ( li ) ;
135
145
api . suggestions . push ( suggestion ) ;
136
146
return li ;
@@ -141,6 +151,7 @@ function horsey (el, options) {
141
151
hide ( ) ;
142
152
attachment . focus ( ) ;
143
153
crossvent . fabricate ( attachment , 'horsey-selected' , value ) ;
154
+ el . setAttribute ( 'aria-activedescendant' , suggestionId ) ;
144
155
}
145
156
146
157
function filterItem ( ) {
@@ -210,13 +221,15 @@ function horsey (el, options) {
210
221
if ( suggestion ) {
211
222
selection = suggestion ;
212
223
selection . className += ' sey-selected' ;
224
+ el . setAttribute ( 'aria-activedescendant' , selection . getAttribute ( 'id' ) ) ;
213
225
}
214
226
}
215
227
216
228
function unselect ( ) {
217
229
if ( selection ) {
218
230
selection . className = selection . className . replace ( / s e y - s e l e c t e d / g, '' ) ;
219
231
selection = null ;
232
+ el . removeAttribute ( 'aria-activedescendant' ) ;
220
233
}
221
234
}
222
235
0 commit comments