From dd6ec67b674c8393618b454a6f2356a7da783c6e Mon Sep 17 00:00:00 2001 From: Shunguo Date: Tue, 20 Feb 2024 13:59:52 -0600 Subject: [PATCH] update the rules for customer checkbox and radio button #1610 --- .../src/v4/rules/element_tabbable_visible.ts | 22 +++-- .../src/v4/util/CSSUtil.ts | 5 +- ...ro-carbon.html => Checkbox-clip-zero.html} | 38 ++++----- .../Radio-clip-zero.html | 84 +++++++++++++++++++ 4 files changed, 122 insertions(+), 27 deletions(-) rename accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_visible_ruleunit/{Elements-clip-zero-carbon.html => Checkbox-clip-zero.html} (72%) create mode 100755 accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_visible_ruleunit/Radio-clip-zero.html diff --git a/accessibility-checker-engine/src/v4/rules/element_tabbable_visible.ts b/accessibility-checker-engine/src/v4/rules/element_tabbable_visible.ts index be6816c14..bd8ed6b08 100644 --- a/accessibility-checker-engine/src/v4/rules/element_tabbable_visible.ts +++ b/accessibility-checker-engine/src/v4/rules/element_tabbable_visible.ts @@ -63,11 +63,23 @@ export let element_tabbable_visible: Rule = { if (defined_styles['position']==='absolute' && defined_styles['clip'] && defined_styles['clip'].replaceAll(' ', '')==='rect(0px,0px,0px,0px)' && !onfocus_styles['clip']) { - // ignore, Carbon design uses proxy for checkbox and radio button, and they are tabbable and visible - let classValue = ruleContext.getAttribute("class"); - if (classValue && (classValue.includes("bx--checkbox") || classValue.includes("cds--checkbox") - || classValue.includes("bx--radio-button") || classValue.includes("cds--radio-button"))) - return RulePass("pass"); + /** + * note that checkbox and radio buttons are automatically tabbable, and an event can be triggered on them by selecting either the button or text + * even though a checkbox or radio button is clipped to 0 size, it is still available to a keyboard or a screen reader + * the rule passes as long as the label text exists and the button on-focus style defined which likely incurs the changes of the text style + */ + if (nodeName === 'input' && (ruleContext.getAttribute('type')==='checkbox' || ruleContext.getAttribute('type')==='radio')) { + const label = RPTUtil.getLabelForElement(ruleContext); + if (label && !RPTUtil.isInnerTextEmpty(label)) { + const focus_styles = getDefinedStyles(ruleContext, ":focus"); + const focus_visible_styles = getDefinedStyles(ruleContext, ":focus-visible"); + const focus_within_styles = getDefinedStyles(ruleContext, ":focus-within"); + const checked_styles = getDefinedStyles(ruleContext, ":checked"); + + if (focus_styles || focus_visible_styles || focus_within_styles || checked_styles) + return RulePass("pass"); + } + } return RulePotential("potential_visible", []); } diff --git a/accessibility-checker-engine/src/v4/util/CSSUtil.ts b/accessibility-checker-engine/src/v4/util/CSSUtil.ts index eca625ef3..58b17c96a 100644 --- a/accessibility-checker-engine/src/v4/util/CSSUtil.ts +++ b/accessibility-checker-engine/src/v4/util/CSSUtil.ts @@ -65,11 +65,14 @@ export function getComputedStyle(elem: HTMLElement, pseudoElt?: PseudoClass) { * for example, for 'transform: rotate(2.5deg);', the computed style returns 'matrix(-0.0436194, 0.999048, -0.999048, -0.0436194, 0, 0)' * and the defined style returns 'rotate(2.5deg)' * + * change the type of the parameter pseudoClass from PseudoClass to string to include both pseudo classes (e.g., :focus, :checked) + * and pseudo elements (e.g., ::before, ::after). + * * @param {HTMLElement} elem * @param {string} [pseudoClass] If specified, will return values that are different * than when the pseudoClass does not match. */ -export function getDefinedStyles(elem: HTMLElement, pseudoClass?: PseudoClass) { +export function getDefinedStyles(elem: HTMLElement, pseudoClass?: string ) { // console.log("Function: getDefinedStyles"); let definedStyles = {}; let definedStylePseudo = {}; diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_visible_ruleunit/Elements-clip-zero-carbon.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_visible_ruleunit/Checkbox-clip-zero.html similarity index 72% rename from accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_visible_ruleunit/Elements-clip-zero-carbon.html rename to accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_visible_ruleunit/Checkbox-clip-zero.html index ebea233d4..d4d17d231 100755 --- a/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_visible_ruleunit/Elements-clip-zero-carbon.html +++ b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_tabbable_visible_ruleunit/Checkbox-clip-zero.html @@ -23,7 +23,7 @@ Test Example -
- - +
+ +
+ + + +