Skip to content

Commit 55f311c

Browse files
committed
Clear selection on uncaught keyboard interactions
These interactions are not used to interact with list results, and we assume they are use to interact with the input, therefore we unselect items.
1 parent 2e8820d commit 55f311c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ function keyboardBindings(event: KeyboardEvent, combobox: Combobox) {
120120
event.preventDefault()
121121
}
122122
break
123+
default:
124+
combobox.clearSelection()
123125
}
124126
}
125127

test/test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,24 @@ describe('combobox-nav', function() {
144144
assert.equal(expectedTargets[1], 'baymax')
145145
})
146146

147+
it('clear selection on input operation', function() {
148+
press(input, 'ArrowDown')
149+
assert.equal(options[0].getAttribute('aria-selected'), 'true')
150+
assert.equal(input.getAttribute('aria-activedescendant'), 'baymax')
151+
152+
press(input, 'ArrowLeft')
153+
assert(!list.querySelector('[aria-selected=true]'), 'Nothing should be selected')
154+
assert(!input.hasAttribute('aria-activedescendant'), 'Nothing should be selected')
155+
156+
press(input, 'ArrowDown')
157+
assert.equal(options[0].getAttribute('aria-selected'), 'true')
158+
assert.equal(input.getAttribute('aria-activedescendant'), 'baymax')
159+
160+
press(input, 'Backspace')
161+
assert(!list.querySelector('[aria-selected=true]'), 'Nothing should be selected')
162+
assert(!input.hasAttribute('aria-activedescendant'), 'Nothing should be selected')
163+
})
164+
147165
it('fires event and follows the link on click', function() {
148166
let eventFired = false
149167
document.addEventListener('combobox-commit', function() {

0 commit comments

Comments
 (0)