This commit is contained in:
Andrew Leach 2024-02-26 17:11:40 +00:00
Родитель 7182ef587d
Коммит dbf90b5355
2 изменённых файлов: 18 добавлений и 3 удалений

Просмотреть файл

@ -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
}

Просмотреть файл

@ -340,8 +340,6 @@ describe('combobox-nav', function () {
<li><del>BB-8</del></li>
<li id="hubot" role="option">Hubot</li>
<li id="r2-d2" role="option">R2-D2</li>
<li id="johnny-5" hidden role="option">Johnny 5</li>
<li id="wall-e" role="option" aria-disabled="true">Wall-E</li>
<li><a href="#link" role="option" id="link">Link</a></li>
</ul>
`
@ -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()