-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomboboxlistbox3.html
59 lines (59 loc) · 2.37 KB
/
comboboxlistbox3.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html id="htmldoc" lang="en-us">
<head>
<style>
.current {
background-color: beige;
}
</style>
<script>
function handleKeydown(event) {
const list = document.getElementById("list");
const lister = document.getElementById("lister");
const currentId = list.getAttribute("aria-activedescendant");
const elem = document.getElementById(currentId);
let next = elem;
if (event.key === 'ArrowDown') {
next = elem.nextElementSibling;
} else if (event.key === 'ArrowUp') {
next = elem.previousElementSibling;
}
if (next) {
list.setAttribute("aria-activedescendant", "item0");
elem.classList.remove("current");
next.classList.add("current");
const container = lister.lastElementChild;
/*container.remove();
if (next.nextElementSibling == null) {
const count = container.childElementCount;
for (let i=1; i<=5; i++) {
const child = document.createElement("div");
child.setAttribute("id", "item"+(count+i));
child.setAttribute("role", "option");
child.setAttribute("aria-selected", "false");
child.textContent = "Item "+(count+i);
container.appendChild(child);
}
}*/
list.appendChild(container);
// setTimeout(() => {
list.setAttribute("aria-activedescendant", next.id);
// }, 1000);
}
}
</script>
</head>
<body>
<input id="list" type="text" role="listbox" tabindex="0" aria-activedescendant="item1" aria-multiselectable="true" onkeydown="handleKeydown(event)"></input>
<div id="lister" >
<div tabindex="-1" role="option" id="item0" style="display: none" aria-selected="false">Update</div>
<div id="container" tabindex="-1" role="presentation">
<div role="option" id="item1" class="current" aria-selected="false">Item 1</div>
<div role="option" id="item2" aria-selected="false" class="">Item 2</div>
<div role="option" id="item3" aria-selected="false" class="">Item 3</div>
<div role="option" id="item4" aria-selected="false" class="">Item 4</div>
<div role="option" id="item5" aria-selected="false" class="">Item 5</div>
</div>
</div>
</body>
</html>