code.gitea.io/gitea@v1.22.3/web_src/js/modules/fomantic/aria.md (about) 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. Files in 6 `web_src/js/modules/fomantic/` are used as a workaround to make the UI more accessible. 7 8 The aria-related code 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 (Option+Up/Down) 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 25 26 # Known Problems 27 28 * Tested with Apple VoiceOver: If a dropdown menu/combobox is opened by mouse click, then arrow keys don't work. 29 But if the dropdown is opened by keyboard Tab, then arrow keys work, and from then on, the keys almost work with mouse click too. 30 The clue: when the dropdown is only opened by mouse click, VoiceOver doesn't send 'keydown' events of arrow keys to the DOM, 31 VoiceOver expects to use arrow keys to navigate between some elements, but it couldn't. 32 Users could use Option+ArrowKeys to navigate between menu/combobox items or selection labels if the menu/combobox is opened by mouse click. 33 34 # Checkbox 35 36 ## Accessibility-friendly Checkbox 37 38 The ideal checkboxes should be: 39 40 ```html 41 <label><input type="checkbox"> ... </label> 42 ``` 43 44 However, the templates still have the Fomantic-style HTML layout: 45 46 ```html 47 <div class="ui checkbox"> 48 <input type="checkbox"> 49 <label>...</label> 50 </div> 51 ``` 52 53 We call `initAriaCheckboxPatch` to link the `input` and `label` which makes clicking the 54 label etc. work. There is still a problem: These checkboxes are not friendly to screen readers, 55 so we add IDs to all the Fomantic UI checkboxes automatically by JS. If the `label` part is empty, 56 then the checkbox needs to get the `aria-label` attribute manually. 57 58 # Fomantic Dropdown 59 60 Fomantic Dropdown is designed to be used for many purposes: 61 62 * Menu (the profile menu in navbar, the language menu in footer) 63 * Popup (the branch/tag panel, the review box) 64 * Simple `<select>` , used in many forms 65 * Searchable option-list with static items (used in many forms) 66 * Searchable option-list with dynamic items (ajax) 67 * Searchable multiple selection option-list with dynamic items: the repo topic setting 68 * More complex usages, like the Issue Label selector 69 70 Fomantic Dropdown requires that the focus must be on its primary element. 71 If the focus changes, it hides or panics. 72 73 At the moment, the aria-related code only tries to partially resolve the a11y problems for dropdowns with items. 74 75 There are different solutions: 76 77 * combobox + listbox + option: 78 * https://www.w3.org/WAI/ARIA/apg/patterns/combobox/ 79 * A combobox is an input widget with an associated popup that enables users to select a value for the combobox from 80 a collection of possible values. In some implementations, the popup presents allowed values, while in other implementations, 81 the popup presents suggested values, and users may either select one of the suggestions or type a value. 82 * menu + menuitem: 83 * https://www.w3.org/WAI/ARIA/apg/patterns/menubar/ 84 * A menu is a widget that offers a list of choices to the user, such as a set of actions or functions. 85 86 The current approach is: detect if the dropdown has an input, 87 if yes, it works like a combobox, otherwise it works like a menu. 88 Multiple selection dropdown is not well-supported yet, it needs more work. 89 90 Some important pages for dropdown testing: 91 92 * Home(dashboard) page, the "Create Repo" / "Profile" / "Language" menu. 93 * Create New Repo page, a lot of dropdowns as combobox. 94 * Collaborators page, the "permission" dropdown (the old behavior was not quite good, it just works). 95 96 ```html 97 <!-- read-only dropdown --> 98 <div class="ui dropdown"> <!-- focused here, then it's not perfect to use aria-activedescendant to point to the menu item --> 99 <input type="hidden" ...> 100 <div class="text">Default</div> 101 <div class="menu" tabindex="-1"> <!-- "transition hidden|visible" classes will be added by $.dropdown() and when the dropdown is working --> 102 <div class="item active selected">Default</div> 103 <div class="item">...</div> 104 </div> 105 </div> 106 107 <!-- search input dropdown --> 108 <div class="ui dropdown"> 109 <input type="hidden" ...> 110 <input class="search" autocomplete="off" tabindex="0"> <!-- focused here --> 111 <div class="text"></div> 112 <div class="menu" tabindex="-1"> <!-- "transition hidden|visible" classes will be added by $.dropdown() and when the dropdown is working --> 113 <div class="item selected">...</div> 114 <div class="item">...</div> 115 </div> 116 </div> 117 ```