Skip to content

Commit 1fbff84

Browse files
committed
always use combobox
1 parent e912d35 commit 1fbff84

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

web_src/js/features/aria.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ function attachOneDropdownAria($dropdown) {
2929
const $focusable = $textSearch.length ? $textSearch : $dropdown; // the primary element for focus, see comment above
3030
if (!$focusable.length) return;
3131

32-
// detect if the dropdown has an input, if yes, it works like a combobox, otherwise it works like a menu
33-
// or use a special class to indicate it's a combobox/menu in the future
34-
const isComboBox = $dropdown.find('input').length > 0;
32+
// There are 2 possible solutions about the role: combobox or menu. Always use combobox, see "aria.md" for details.
33+
const isComboBox = true; // $dropdown.find('input').length > 0;
3534

3635
const focusableRole = isComboBox ? 'combobox' : 'button';
3736
const listPopupRole = isComboBox ? 'listbox' : 'menu';
@@ -44,6 +43,7 @@ function attachOneDropdownAria($dropdown) {
4443
$item.find('a').attr('tabindex', '-1'); // as above, the elements inside the dropdown menu item should not be focusable, the focus should always be on the dropdown primary element.
4544
}
4645

46+
// delegate the dropdown's template function to add aria attributes
4747
const dropdownTemplates = {...$dropdown.dropdown('setting', 'templates')};
4848
const dropdownTemplatesMenuOld = dropdownTemplates.menu;
4949
dropdownTemplates.menu = function(response, fields, preserveHTML, className) {
@@ -70,6 +70,7 @@ function attachOneDropdownAria($dropdown) {
7070
// this role could only be changed after its content is ready, otherwise some browsers+readers (like Chrome+AppleVoice) crash
7171
$menu.attr('role', listPopupRole);
7272

73+
// make the primary element (focusable) aria-friendly
7374
$focusable.attr({
7475
'role': $focusable.attr('role') ?? focusableRole,
7576
'aria-haspopup': listPopupRole,

web_src/js/features/aria.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,21 @@ There are different solutions:
4848

4949
## Fomantic UI Dropdown
5050

51-
When the dropdown has input elements, use `role=combobox`, otherwise use `role=menu` (see `aria.js`) for actions.
51+
There are 2 possible solutions about the role: combobox or menu
52+
53+
1. Detect if the dropdown has an input, if yes, it works like a combobox, otherwise it works like a menu
54+
2. Always use "combobox", never use "menu"
55+
56+
According to the public discussion with fsologureng in chat channel, we think it's better to use "combobox" for all dropdowns.
57+
58+
> On the old web there were many menus implemented with an auto-submit select,
59+
> but that didn't change the fact that they were selects for screen readers.
60+
> That is the case with Fomantic dropdowns as used in Gitea.
61+
> Implementations of auto-submit select menus fell behind in modern web design precisely because they are not usable or accessible."
62+
>
63+
> We can mark all "dropdown" as "combobox", never use "menu" in code. Do you think this solution is clear enough?
64+
>
65+
> Yes. I think it will provide better accessibility because is more coherent with the current fomantic based implementation.
5266
5367
Reference:
5468

0 commit comments

Comments
 (0)