Skip to content

Commit 87e64c2

Browse files
authored
Merge pull request #4 from github/disabled
Prevent disabled items from being committed
2 parents 6306e95 + daaa38e commit 87e64c2

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

combobox-nav.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function commitWithElement(event: MouseEvent) {
6969

7070
function commit(input: HTMLTextAreaElement | HTMLInputElement, list: HTMLElement): boolean {
7171
const target = list.querySelector('[aria-selected="true"]')
72-
if (!target) return false
72+
if (!target || target.getAttribute('aria-disabled') === 'true') return false
7373
fireCommitEvent(target)
7474
return true
7575
}

test/test.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('combobox-nav', function() {
4646
<li><del>BB-8</del></li>
4747
<li id="hubot" role="option">Hubot</li>
4848
<li id="r2-d2" role="option">R2-D2</li>
49+
<li id="wall-e" role="option" aria-disabled="true">Wall-E</li>
4950
</ul>
5051
`
5152
comboboxNav.install(document.querySelector('input'), document.querySelector('ul'))
@@ -79,18 +80,23 @@ describe('combobox-nav', function() {
7980
assert.equal(options[3].getAttribute('aria-selected'), 'true')
8081
assert.equal(input.getAttribute('aria-activedescendant'), 'r2-d2')
8182

83+
press(input, 'n', true)
84+
assert.equal(options[4].getAttribute('aria-selected'), 'true')
85+
assert.equal(input.getAttribute('aria-activedescendant'), 'wall-e')
86+
press(input, 'Enter')
87+
8288
press(input, 'p', true)
83-
assert.equal(options[2].getAttribute('aria-selected'), 'true')
84-
assert.equal(input.getAttribute('aria-activedescendant'), 'hubot')
89+
assert.equal(options[3].getAttribute('aria-selected'), 'true')
90+
assert.equal(input.getAttribute('aria-activedescendant'), 'r2-d2')
8591

8692
press(input, 'ArrowUp')
87-
assert.equal(options[0].getAttribute('aria-selected'), 'true')
88-
assert.equal(input.getAttribute('aria-activedescendant'), 'baymax')
93+
assert.equal(options[2].getAttribute('aria-selected'), 'true')
94+
assert.equal(input.getAttribute('aria-activedescendant'), 'hubot')
8995

9096
press(input, 'Enter')
9197
assert.equal(expectedTargets.length, 2)
9298
assert.equal(expectedTargets[0], 'hubot')
93-
assert.equal(expectedTargets[1], 'baymax')
99+
assert.equal(expectedTargets[1], 'hubot')
94100
})
95101

96102
it('fires commit events on click', function() {

0 commit comments

Comments
 (0)