diff --git a/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts b/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts index 9b78b05c0..8e396b82c 100644 --- a/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts +++ b/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts @@ -436,7 +436,45 @@ export class RPTUtil { if (!allowedRoles && allowedRoles.length === 0) return false; - const parent = element.parentElement; + let parent = element.parentElement; + // datalist, fieldset, optgroup, etc. may be just used for grouping purpose, so go up to the parent + while (parent && roles.some(role => role === 'group')) + parent = parent.parentElement; + + if (parent && (parent.hasAttribute("tabindex") || RPTUtil.isTabbable(parent))) { + const target_roles =["listitem", "menuitem", "menuitemcheckbox", "menuitemradio", "option", "radio", "switch", "treeitem"]; + if (allowedRoles.includes('any') || roles.some(role => target_roles.includes(role))) + return true; + } + return false; + } + + /** + * an "inline" CSS display property tells the element to fit itself on the same line. An 'inline' element's width and height are ignored. + * some element has default inline property, such as , , + * most formatting elements inherent inline property, such as , , , + * an "inline-block" element still place element in the same line without breaking the line, but the element's width and height are applied. + */ + public static isInline(element) { + if (!element) return false; + + const inline_elements = ["listitem", "menuitem", "menuitemcheckbox", "menuitemradio", "option", "radio", "switch", "treeitem"]; + if (element.hasAttribute("tabindex") || RPTUtil.isTabbable(element)) return true; + + const roles = RPTUtil.getRoles(element, true); + if (!roles && roles.length === 0) + return false; + + let tagProperty = RPTUtil.getElementAriaProperty(element); + let allowedRoles = RPTUtil.getAllowedAriaRoles(element, tagProperty); + if (!allowedRoles && allowedRoles.length === 0) + return false; + + let parent = element.parentElement; + // datalist, fieldset, optgroup, etc. may be just used for grouping purpose, so go up to the parent + while (parent && roles.some(role => role === 'group')) + parent = parent.parentElement; + if (parent && (parent.hasAttribute("tabindex") || RPTUtil.isTabbable(parent))) { const target_roles =["listitem", "menuitem", "menuitemcheckbox", "menuitemradio", "option", "radio", "switch", "treeitem"]; if (allowedRoles.includes('any') || roles.some(role => target_roles.includes(role))) diff --git a/accessibility-checker-engine/src/v4/rules/index.ts b/accessibility-checker-engine/src/v4/rules/index.ts index f9430b5e7..d3988e786 100644 --- a/accessibility-checker-engine/src/v4/rules/index.ts +++ b/accessibility-checker-engine/src/v4/rules/index.ts @@ -175,6 +175,7 @@ export * from "./table_layout_linearized" export * from "./table_scope_valid" export * from "./table_structure_misuse" export * from "./table_summary_redundant" +export * from "./target_spacing_sufficient" export * from "./text_block_heading" export * from "./text_contrast_sufficient" export * from "./text_quoted_correctly" diff --git a/accessibility-checker-engine/src/v4/rules/target_spacing_sufficient.ts b/accessibility-checker-engine/src/v4/rules/target_spacing_sufficient.ts index 4c8311f7f..7993bc346 100644 --- a/accessibility-checker-engine/src/v4/rules/target_spacing_sufficient.ts +++ b/accessibility-checker-engine/src/v4/rules/target_spacing_sufficient.ts @@ -50,7 +50,7 @@ act: [], run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => { const ruleContext = context["dom"].node as HTMLElement; - if (!VisUtil.isNodeVisible(ruleContext) || (!RPTUtil.isTabbable(ruleContext) && !ruleContext .hasAttribute("tabindex"))) + if (!VisUtil.isNodeVisible(ruleContext) || (!RPTUtil.isTarget(ruleContext))) return null; const nodeName = ruleContext.nodeName.toLocaleLowerCase(); diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/target_spacing_sufficient_ruleunit/block_element_inline.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/target_spacing_sufficient_ruleunit/block_element_inline.html new file mode 100755 index 000000000..204c8c8dc --- /dev/null +++ b/accessibility-checker-engine/test/v2/checker/accessibility/rules/target_spacing_sufficient_ruleunit/block_element_inline.html @@ -0,0 +1,116 @@ + + + + + + + + RPT Test Suite + + + + + +

The display Property

+ +

display: inline

+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum consequat scelerisque elit sit amet consequat. Aliquam erat volutpat. Aliquam gravida nisl sit amet facilisis. Nullam cursus fermentum velit sed laoreet.
+ +

display: inline-block

+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum consequat scelerisque elit sit amet consequat. Aliquam erat volutpat. Aliquam venenatis gravida nisl sit amet facilisis. Nullam cursus fermentum velit sed laoreet.
+ +

display: block

+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum consequat scelerisque elit sit amet consequat. Aliquam erat volutpat. Aliquam venenatis gravida nisl sit amet facilisis. Nullam cursus fermentum velit sed laoreet.
+ + + + + + + diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/target_spacing_sufficient_ruleunit/element_inline.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/target_spacing_sufficient_ruleunit/element_inline.html new file mode 100755 index 000000000..013531b8e --- /dev/null +++ b/accessibility-checker-engine/test/v2/checker/accessibility/rules/target_spacing_sufficient_ruleunit/element_inline.html @@ -0,0 +1,121 @@ + + + + + + + + RPT Test Suite + + + + + +

The display Property

+ +

display: inline

+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum consequat scelerisque elit sit amet consequat. Aliquam erat volutpat. + Aliquam + + gravida nisl sit amet facilisis. Nullam cursus fermentum velit sed laoreet. +
+ +

display: inline-block

+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum consequat scelerisque elit sit amet consequat. Aliquam erat volutpat. Aliquam venenatis gravida nisl sit amet facilisis. Nullam cursus fermentum velit sed laoreet.
+ +

display: block

+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum consequat scelerisque elit sit amet consequat. Aliquam erat volutpat. Aliquam venenatis gravida nisl sit amet facilisis. Nullam cursus fermentum velit sed laoreet.
+ + + + + + +