Skip to content

Commit 87711f2

Browse files
committed
Update combobox css for improved a11y
1 parent ee46a29 commit 87711f2

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

app/javascript/controllers/searches/combobox.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const cancel = (event) => {
99
event.preventDefault();
1010
};
1111

12+
/* When the index is out of bounds, return the first or last item */
1213
function cyclingValueAt(array, index) {
1314
const first = 0;
1415
const last = array.length - 1;
@@ -20,7 +21,7 @@ function cyclingValueAt(array, index) {
2021

2122
export default class extends Controller {
2223
connect() {
23-
console.log('Connected', this.element, this.listbox, this.combobox);
24+
console.log('Connected');
2425
}
2526

2627
selectIndex(index) {
@@ -60,7 +61,6 @@ export default class extends Controller {
6061
}
6162

6263
navigate(event) {
63-
console.log('Navigating', event); // event.key, e.g. "ArrowDown"
6464
this.navigationKeyHandlers[event.key]?.call(this, event);
6565
}
6666

@@ -69,7 +69,7 @@ export default class extends Controller {
6969
}
7070

7171
get selectedItem() {
72-
return this.element.querySelector('.selected');
72+
return this.element.querySelector('[role="option"].selected');
7373
}
7474

7575
get selectedItemIndex() {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
.combobox {
2+
cursor: pointer;
3+
24
& ul {
35
list-style-type: none;
46
padding: 0;
57
margin: 0;
68
}
79

10+
/*
11+
* Note: Because transparent borders are visible on some systems with operating system high contrast settings enabled, transparency cannot be used to create a visual difference between the element that is focused and other elements. Instead of using transparency, the focused element has a thicker border and less padding. When an element receives focus, its border changes from zero to two pixels and padding is reduced by two pixels. When an element loses focus, its border changes from two pixels to two and padding is increased by two pixels.
12+
* Courtesy https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-autocomplete-list/
13+
*/
814
& [role='option'] {
15+
padding: 2px;
16+
917
&:hover {
1018
background-color: var(--joy-block-hover);
1119
}
1220

1321
&.selected {
22+
padding: 0;
23+
1424
background-color: var(--joy-block-selected);
25+
border: 2px solid var(--joy-border-bold);
1526
}
1627
}
1728
}

app/javascript/css/config/theme.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@
6161

6262
--joy-border-quiet: var(--joy-color-100);
6363
--joy-border-subtle: var(--joy-color-300);
64+
--joy-border-bold: var(--joy-color-700);
6465
--joy-border: var(--joy-color-600);
66+
6567
--joy-color-quote: var(--joy-color-600);
6668

6769
--joy-text: var(--color-dark);
@@ -117,6 +119,7 @@
117119

118120
--joy-border-quiet: var(--joy-color-900);
119121
--joy-border-subtle: var(--joy-color-800);
122+
--joy-border-bold: var(--joy-color-400);
120123
--joy-border: var(--joy-color-600);
121124

122125
--joy-text: var(--joy-color-50);

app/views/searches/listbox.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def view_template
2020
)) do
2121
if pages.any?
2222
pages.each.with_index do |page, i|
23-
li(role: "option", id: dom_id(page, "search-option")) do
23+
li(role: "option", id: dom_id(page, "search-option"), class: "rounded") do
2424
a(
2525
href: page.request_path,
2626
data: {

0 commit comments

Comments
 (0)