I am implementing the following combobox: https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/
As you can notice from the example code in the link above, when I click with my mouse on the combobox, there is a blue focus around the selected option in the listbox.
How do I remove this focus when interacting with the combobox using mouse? I would like to keep the focus when interacting with the combox using keyboard only.
2
Answers
The CSS selector
:focus-visible
that is targeting only the elements that were focused via keyboard input.Info about browser support on caniuse.
The
.combo-input:focus
makes the mouse on click focus on the listbox’s header only. Changing it to.combo-input:focus-visible
, will only change that. In order to change how to options behave, we’d need to change the JavaScript.Adding to what iorgv said, you should also consider keeping the
:focus
pseudo-class as some older browser versions do not support:focus-visible
. You can achieve that using the@support
rule:More on that at: MDN focus-visible