Skip to content

Commit e42624a

Browse files
committed
remove unrelated code and comments, add more documents
1 parent a040544 commit e42624a

File tree

2 files changed

+57
-55
lines changed

2 files changed

+57
-55
lines changed

web_src/js/features/aria.js

-10
Original file line numberDiff line numberDiff line change
@@ -127,41 +127,31 @@ function attachOneDropdownAria($dropdown) {
127127
// * desktop event sequence: mousedown -> focus -> mouseup -> click
128128
// * mobile event sequence: focus -> mousedown -> mouseup -> click
129129
// Fomantic may stop propagation of blur event, use capture to make sure we can still get the event
130-
// keep the debug code for developers who want to confirm&debug this code for different browsers (without attaching a remote debugger)
131-
const showDebug = false;
132-
const debug = (msg) => showDebug && $('.page-content').append($('<div>').text(`${$menu.attr('id')} ${msg}, menu visible=${isMenuVisible()}`));
133130
let ignoreClickPreEvents = 0, ignoreClickPreVisible = 0;
134131
$dropdown[0].addEventListener('mousedown', (e) => {
135-
debug(e.type);
136132
ignoreClickPreVisible += isMenuVisible() ? 1 : 0;
137133
ignoreClickPreEvents++;
138134
}, true);
139135
$dropdown[0].addEventListener('focus', (e) => {
140-
debug(e.type);
141136
ignoreClickPreVisible += isMenuVisible() ? 1 : 0;
142137
ignoreClickPreEvents++;
143138
deferredRefreshAria();
144139
}, true);
145140
$dropdown[0].addEventListener('blur', (e) => {
146-
debug(e.type);
147141
ignoreClickPreVisible = ignoreClickPreEvents = 0;
148142
deferredRefreshAria(100);
149143
}, true);
150144
$dropdown[0].addEventListener('mouseup', (e) => {
151-
debug(e.type);
152145
setTimeout(() => {
153-
debug(`${e.type} (deferred)`);
154146
ignoreClickPreVisible = ignoreClickPreEvents = 0;
155147
deferredRefreshAria(100);
156148
}, 0);
157149
}, true);
158150
$dropdown[0].addEventListener('click', (e) => {
159-
debug(`${e.type}, pre-visible=${ignoreClickPreVisible}, pre-events=${ignoreClickPreEvents}`);
160151
if (isMenuVisible() &&
161152
ignoreClickPreVisible !== 2 && // dropdown is switch from invisible to visible
162153
ignoreClickPreEvents === 2 // the click event is related to mousedown+focus
163154
) {
164-
debug(`${e.type}, stop click propagation`);
165155
e.stopPropagation(); // if the dropdown menu has been opened by focus, do not trigger the next click event again
166156
}
167157
ignoreClickPreEvents = ignoreClickPreVisible = 0;

web_src/js/features/aria.md

+57-45
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
**This document is used as aria/a11y reference for future developers**
1+
# Background
2+
3+
This document is used as aria/accessibility(a11y) reference for future developers.
4+
5+
There are a lot of a11y problems in the Fomantic UI library. This `aria.js` is used
6+
as a workaround to make the UI more accessible.
7+
8+
The `aria.js` is designed to avoid touching the official Fomantic UI library,
9+
and to be as independent as possible, so it can be easily modified/removed in the future.
10+
11+
To test the aria/accessibility with screen readers, developers can use the following steps:
12+
13+
* On macOS, you can use VoiceOver.
14+
* Press `Command + F5` to turn on VoiceOver.
15+
* Try to operate the UI with keyboard-only.
16+
* Use Tab/Shift+Tab to switch focus between elements.
17+
* Arrow keys to navigate between menu/combobox items (only aria-active, not really focused).
18+
* Press Enter to trigger the aria-active element.
19+
* On Android, you can use TalkBack.
20+
* Go to Settings -> Accessibility -> TalkBack, turn it on.
21+
* Long-press or press+swipe to switch the aria-active element (not really focused).
22+
* Double-tap means old single-tap on the aria-active element.
23+
* Double-finger swipe means old single-finger swipe.
24+
* TODO: on Windows, on Linux, on iOS
225

326
# Checkbox
427

@@ -10,7 +33,8 @@ The ideal checkboxes should be:
1033
<label><input type="checkbox"> ... </label>
1134
```
1235

13-
However, related styles aren't supported (not implemented) yet, so at the moment, almost all the checkboxes are still using Fomantic UI checkbox.
36+
However, related CSS styles aren't supported (not implemented) yet, so at the moment,
37+
almost all the checkboxes are still using Fomantic UI checkbox.
1438

1539
## Fomantic UI Checkbox
1640

@@ -21,64 +45,52 @@ However, related styles aren't supported (not implemented) yet, so at the moment
2145
</div>
2246
```
2347

24-
Then the JS `$.checkbox()` should be called to make it work with keyboard and label-clicking, then it works like the ideal checkboxes.
48+
Then the JS `$.checkbox()` should be called to make it work with keyboard and label-clicking,
49+
then it works like the ideal checkboxes.
2550

26-
There is still a problem: Fomantic UI checkbox is not friendly to screen readers, so we add IDs to all the Fomantic UI checkboxes automatically by JS.
51+
There is still a problem: Fomantic UI checkbox is not friendly to screen readers,
52+
so we add IDs to all the Fomantic UI checkboxes automatically by JS.
53+
If the `label` part is empty, then the checkbox needs to get the `aria-label` attribute manually.
2754

2855
# Dropdown
2956

30-
## ARIA Dropdown
31-
32-
There are different solutions:
33-
34-
* combobox + listbox + option
35-
* menu + menuitem
36-
37-
```html
38-
<div>
39-
<input role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="the-menu-listbox" aria-activedescendant="item-id-123456">
40-
<ul id="the-menu-listbox" role="listbox">
41-
<li role="option" id="item-id-123456" aria-selected="true">
42-
<a tabindex="-1" href="....">....</a>
43-
</li>
44-
</ul>
45-
</div>
46-
```
47-
48-
4957
## Fomantic UI Dropdown
5058

51-
There are 2 possible solutions about the role: combobox or menu
59+
Fomantic Dropdown is designed to be used for many purposes:
5260

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"
61+
* Menu (the profile menu in navbar, the language menu in footer)
62+
* Popup (the branch/tag panel, the review box)
63+
* Simple `<select>` , used in many forms
64+
* Searchable option-list with static items (used in many forms)
65+
* Searchable option-list with dynamic items (ajax)
66+
* Searchable multiple selection option-list with dynamic items: the repo topic setting
67+
* More complex usages, like the Issue Label selector
5568

56-
According to the public discussion with fsologureng in chat channel:
69+
Fomantic Dropdown requires that the focus must be on its primary element.
70+
If the focus changes, it hides or panics.
5771

58-
> 2023-03-13 14:52:00 UTC
59-
>
60-
> wxiaoguang: Yup, the "language dropdown" is arguable (menu or combobox). It's the only one we need to mark it as combobox if you strongly prefer.
61-
> But for others (Create Repo / Profile / Reaction Menu / Issue Context Menu), I think they are not suitable to be combobox.
62-
>
63-
> fsologureng: I repeat an argument stated in my first comment: "On the old web there were many menus implemented with an auto-submit select,
64-
> but that didn't change the fact that they were selects for screen readers.
65-
> That is the case with Fomantic dropdowns as used in Gitea.
66-
> Implementations of auto-submit select menus fell behind in modern web design precisely because they are not usable or accessible."
67-
>
68-
> wxiaoguang: If you strongly prefer, we can mark all "dropdown" as "combobox", never use "menu" in code. Do you think this solution is clear enough?
69-
>
70-
> fsologureng: Yes. I think it will provide better accessibility because is more coherent with the current fomantic based implementation.
72+
At the moment, `aria.js` only tries to partially resolve the a11y problems for dropdowns with items.
7173

72-
Reference:
74+
There are different solutions:
7375

74-
* Combobox:
76+
* combobox + listbox + option:
7577
* https://www.w3.org/WAI/ARIA/apg/patterns/combobox/
76-
* A combobox is an **input widget** with an associated popup that enables users to select a value for the combobox from
78+
* A combobox is an input widget with an associated popup that enables users to select a value for the combobox from
7779
a collection of possible values. In some implementations, the popup presents allowed values, while in other implementations,
7880
the popup presents suggested values, and users may either select one of the suggestions or type a value.
79-
* Menu:
81+
* menu + menuitem:
8082
* https://www.w3.org/WAI/ARIA/apg/patterns/menubar/
81-
* A menu is a widget that offers a list of choices to the user, such as a set of **actions or functions**.
83+
* A menu is a widget that offers a list of choices to the user, such as a set of actions or functions.
84+
85+
The current approach is: detect if the dropdown has an input,
86+
if yes, it works like a combobox, otherwise it works like a menu.
87+
Multiple selection dropdown is not well-supported yet, it needs more work.
88+
89+
Some important pages for dropdown testing:
90+
91+
* Home(dashboard) page, the "Create Repo" / "Profile" / "Language" menu.
92+
* Create New Repo page, a lot of dropdowns as combobox.
93+
* Collaborators page, the "permission" dropdown (the old behavior was not quite good, it just works).
8294

8395
```html
8496
<!-- read-only dropdown -->

0 commit comments

Comments
 (0)