From ae3268ca92d7a12b3b8e636461996659dc364d10 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 25 Jan 2023 12:20:22 +0800 Subject: [PATCH 1/2] fix checkbox aria --- web_src/js/features/aria.js | 12 ++++++++++++ web_src/js/features/common-global.js | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/web_src/js/features/aria.js b/web_src/js/features/aria.js index 162843678bb45..2e041e1ee41fd 100644 --- a/web_src/js/features/aria.js +++ b/web_src/js/features/aria.js @@ -98,3 +98,15 @@ function attachOneDropdownAria($dropdown) { export function attachDropdownAria($dropdowns) { $dropdowns.each((_, e) => attachOneDropdownAria($(e))); } + +export function attachCheckboxAria($checkboxes) { + $checkboxes.checkbox(); + 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); + } +} diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 442a83980ce6b..4677eeac0c850 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -4,7 +4,7 @@ import {mqBinarySearch} from '../utils.js'; import {createDropzone} from './dropzone.js'; import {initCompColorPicker} from './comp/ColorPicker.js'; import {showGlobalErrorMessage} from '../bootstrap.js'; -import {attachDropdownAria} from './aria.js'; +import {attachCheckboxAria, attachDropdownAria} from './aria.js'; import {handleGlobalEnterQuickSubmit} from './comp/QuickSubmit.js'; import {initTooltip} from '../modules/tippy.js'; import {svg} from '../svg.js'; @@ -111,7 +111,7 @@ export function initGlobalCommon() { }); attachDropdownAria($uiDropdowns); - $('.ui.checkbox').checkbox(); + attachCheckboxAria($('.ui.checkbox')); $('.tabular.menu .item').tab(); $('.tabable.menu .item').tab(); From 9b94b39ca325a824143fb26242091196e08aec03 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 25 Jan 2023 12:55:48 +0800 Subject: [PATCH 2/2] add comments --- web_src/js/features/aria.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web_src/js/features/aria.js b/web_src/js/features/aria.js index 2e041e1ee41fd..a5ac84e4464c5 100644 --- a/web_src/js/features/aria.js +++ b/web_src/js/features/aria.js @@ -101,6 +101,11 @@ export function attachDropdownAria($dropdowns) { export function attachCheckboxAria($checkboxes) { $checkboxes.checkbox(); + + // Fomantic UI checkbox needs to be something like:
+ // It doesn't work well with + // 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');