From dbf90b53556067ff58182659e549150c2fd9033c Mon Sep 17 00:00:00 2001 From: Andrew Leach Date: Mon, 26 Feb 2024 17:11:40 +0000 Subject: [PATCH] Small test --- src/index.ts | 2 +- test/test.js | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9c85298..35efe6e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -108,7 +108,7 @@ export default class Combobox { const focusIndex = els.indexOf(focusEl) if ((focusIndex === els.length - 1 && indexDiff === 1) || (focusIndex === 0 && indexDiff === -1)) { - this.resetSelection() + this.clearSelection() this.input.focus() return } diff --git a/test/test.js b/test/test.js index 0368285..a39d783 100644 --- a/test/test.js +++ b/test/test.js @@ -340,8 +340,6 @@ describe('combobox-nav', function () {
  • BB-8
  • Hubot
  • R2-D2
  • - -
  • Wall-E
  • Link
  • ` @@ -373,6 +371,23 @@ describe('combobox-nav', function () { assert.equal(list.children[0].getAttribute('aria-selected'), 'true') }) + it('pressing key down off the last item will have no items selected', () => { + // Get all visible options in the list + const options = document.querySelectorAll('[role=option]:not([aria-hidden=true])') + // Key press down for each item and ensure the next is selected + for (let i = 0; i < options.length; i++) { + if (i > 0) { + assert.equal(options[i - 1].getAttribute('aria-selected'), null) + } + + assert.equal(options[i].getAttribute('aria-selected'), 'true') + press(input, 'ArrowDown') + } + + const selected = document.querySelectorAll('[aria-selected]') + assert.equal(selected.length, 0) + }) + it('indicates first option when restarted', () => { combobox.stop() combobox.start()