Skip to content

Commit 2e8820d

Browse files
committed
Add support for ArrowDown opening the list
1 parent 8b2dbd5 commit 2e8820d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

examples/index.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,22 @@
2828
const list = document.querySelector('ul')
2929
const comboboxController = new Combobox(input, list)
3030

31-
function toggleList() {
32-
const hidden = input.value.length === 0
31+
function toggleList(show) {
32+
const hidden = show === true ? false : input.value.length === 0
3333
if (hidden) {
3434
comboboxController.stop()
3535
} else {
3636
comboboxController.start()
3737
}
3838
list.hidden = hidden
3939
}
40-
input.addEventListener('input', toggleList)
41-
input.addEventListener('focus', toggleList)
40+
input.addEventListener('keydown', event => {
41+
if (event.key !== 'ArrowDown' || !list.hidden) return
42+
toggleList(true)
43+
comboboxController.navigate(1)
44+
})
45+
input.addEventListener('input', () => toggleList())
46+
input.addEventListener('focus', () => toggleList())
4247
input.addEventListener('blur', () => {
4348
list.hidden = true
4449
comboboxController.clearSelection()

0 commit comments

Comments
 (0)