mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-26 12:27:06 +00:00 
			
		
		
		
	Add ARIA support for Fomantic UI checkboxes (#22599)
Replace #22593 This is a general approach to add ARIA support for all Fomantic UI checkboxes (including radioboxes) * Pros: * General approach, it works for all Fomantic UI checkboxes / radioboxes * No need to write IDs manually everywhere * No need to tell new contributors to write IDs again and again * Cons: * Slightly affects performance, but it's really trivial, because there was already a heavy `$('.ui.checkbox').checkbox()` for Fomantic UI before. So everything is still fine. Screenshot (from the repo setting page, which has various checkboxes): <details>  </details>
This commit is contained in:
		| @@ -98,3 +98,20 @@ function attachOneDropdownAria($dropdown) { | ||||
| export function attachDropdownAria($dropdowns) { | ||||
|   $dropdowns.each((_, e) => attachOneDropdownAria($(e))); | ||||
| } | ||||
|  | ||||
| export function attachCheckboxAria($checkboxes) { | ||||
|   $checkboxes.checkbox(); | ||||
|  | ||||
|   // Fomantic UI checkbox needs to be something like: <div class="ui checkbox"><label /><input /></div> | ||||
|   // It doesn't work well with <label><input />...</label> | ||||
|   // To make it work with aria, the "id"/"for" attributes are necessary, so add them automatically if missing. | ||||
|   // In the future, refactor to use native checkbox directly, then this patch could be removed. | ||||
|   for (const el of $checkboxes) { | ||||
|     const label = el.querySelector('label'); | ||||
|     const input = el.querySelector('input'); | ||||
|     if (!label || !input || input.getAttribute('id')) continue; | ||||
|     const id = generateAriaId(); | ||||
|     input.setAttribute('id', id); | ||||
|     label.setAttribute('for', id); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 wxiaoguang
					wxiaoguang