Skip to content

Commit e130b77

Browse files
committed
Add support for Home and End keys
The [WAI ARIA Practices 1.1][listbox-keyboard] outlines optional support for [`Home` and `End` keys][keys] to jump to the top and bottom of the listbox, respectively. [listbox-keyboard]: https://www.w3.org/TR/wai-aria-practices-1.1/#listbox-popup-keyboard-interaction [keys]: https://www.w3.org/TR/uievents-key/#keys-navigation
1 parent 4ae6175 commit e130b77

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ function keyboardBindings(event: KeyboardEvent, combobox: Combobox) {
120120
combobox.navigate(-1)
121121
event.preventDefault()
122122
break
123+
case 'Home':
124+
combobox.clearSelection()
125+
combobox.navigate(1)
126+
event.preventDefault()
127+
break
128+
case 'End':
129+
combobox.clearSelection()
130+
combobox.navigate(-1)
131+
event.preventDefault()
132+
break
123133
case 'n':
124134
if (ctrlBindings && event.ctrlKey) {
125135
combobox.navigate(1)

test/test.js

+8
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ describe('combobox-nav', function() {
138138
assert.equal(options[5].getAttribute('aria-selected'), 'true')
139139
assert.equal(input.getAttribute('aria-activedescendant'), 'link')
140140

141+
press(input, 'Home')
142+
assert.equal(options[0].getAttribute('aria-selected'), 'true')
143+
assert.equal(input.getAttribute('aria-activedescendant'), 'baymax')
144+
145+
press(input, 'End')
146+
assert.equal(options[5].getAttribute('aria-selected'), 'true')
147+
assert.equal(input.getAttribute('aria-activedescendant'), 'link')
148+
141149
press(input, 'Enter')
142150
assert.equal(expectedTargets.length, 2)
143151
assert.equal(expectedTargets[0], 'hubot')

0 commit comments

Comments
 (0)