зеркало из https://github.com/github/combobox-nav.git
Small test
This commit is contained in:
Родитель
7182ef587d
Коммит
dbf90b5355
|
@ -108,7 +108,7 @@ export default class Combobox {
|
||||||
const focusIndex = els.indexOf(focusEl)
|
const focusIndex = els.indexOf(focusEl)
|
||||||
|
|
||||||
if ((focusIndex === els.length - 1 && indexDiff === 1) || (focusIndex === 0 && indexDiff === -1)) {
|
if ((focusIndex === els.length - 1 && indexDiff === 1) || (focusIndex === 0 && indexDiff === -1)) {
|
||||||
this.resetSelection()
|
this.clearSelection()
|
||||||
this.input.focus()
|
this.input.focus()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
19
test/test.js
19
test/test.js
|
@ -340,8 +340,6 @@ describe('combobox-nav', function () {
|
||||||
<li><del>BB-8</del></li>
|
<li><del>BB-8</del></li>
|
||||||
<li id="hubot" role="option">Hubot</li>
|
<li id="hubot" role="option">Hubot</li>
|
||||||
<li id="r2-d2" role="option">R2-D2</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>
|
<li><a href="#link" role="option" id="link">Link</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
`
|
`
|
||||||
|
@ -373,6 +371,23 @@ describe('combobox-nav', function () {
|
||||||
assert.equal(list.children[0].getAttribute('aria-selected'), 'true')
|
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', () => {
|
it('indicates first option when restarted', () => {
|
||||||
combobox.stop()
|
combobox.stop()
|
||||||
combobox.start()
|
combobox.start()
|
||||||
|
|
Загрузка…
Ссылка в новой задаче