diff --git a/combobox-nav.js b/combobox-nav.js
index 02dbf54..58655c3 100644
--- a/combobox-nav.js
+++ b/combobox-nav.js
@@ -69,7 +69,7 @@ function commitWithElement(event: MouseEvent) {
function commit(input: HTMLTextAreaElement | HTMLInputElement, list: HTMLElement): boolean {
const target = list.querySelector('[aria-selected="true"]')
- if (!target) return false
+ if (!target || target.getAttribute('aria-disabled') === 'true') return false
fireCommitEvent(target)
return true
}
diff --git a/test/test.js b/test/test.js
index b8e9bd1..bbf681c 100644
--- a/test/test.js
+++ b/test/test.js
@@ -46,6 +46,7 @@ describe('combobox-nav', function() {
BB-8
Hubot
R2-D2
+ Wall-E
`
comboboxNav.install(document.querySelector('input'), document.querySelector('ul'))
@@ -79,18 +80,23 @@ describe('combobox-nav', function() {
assert.equal(options[3].getAttribute('aria-selected'), 'true')
assert.equal(input.getAttribute('aria-activedescendant'), 'r2-d2')
+ press(input, 'n', true)
+ assert.equal(options[4].getAttribute('aria-selected'), 'true')
+ assert.equal(input.getAttribute('aria-activedescendant'), 'wall-e')
+ press(input, 'Enter')
+
press(input, 'p', true)
- assert.equal(options[2].getAttribute('aria-selected'), 'true')
- assert.equal(input.getAttribute('aria-activedescendant'), 'hubot')
+ assert.equal(options[3].getAttribute('aria-selected'), 'true')
+ assert.equal(input.getAttribute('aria-activedescendant'), 'r2-d2')
press(input, 'ArrowUp')
- assert.equal(options[0].getAttribute('aria-selected'), 'true')
- assert.equal(input.getAttribute('aria-activedescendant'), 'baymax')
+ assert.equal(options[2].getAttribute('aria-selected'), 'true')
+ assert.equal(input.getAttribute('aria-activedescendant'), 'hubot')
press(input, 'Enter')
assert.equal(expectedTargets.length, 2)
assert.equal(expectedTargets[0], 'hubot')
- assert.equal(expectedTargets[1], 'baymax')
+ assert.equal(expectedTargets[1], 'hubot')
})
it('fires commit events on click', function() {