From 91b04e26c7e4faf4868fa2b8870ceae75f69904d Mon Sep 17 00:00:00 2001 From: Mu-An Chiou Date: Fri, 4 Jan 2019 17:43:24 -0500 Subject: [PATCH 1/2] Add test to ensure disabled item does not get committed --- test/test.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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() { From daaa38ee48ac437b4a76f579e2957c8a4abe3b59 Mon Sep 17 00:00:00 2001 From: Mu-An Chiou Date: Fri, 4 Jan 2019 17:44:53 -0500 Subject: [PATCH 2/2] Prevent disabled item from being committed --- combobox-nav.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 }