Skip to content

Commit

Permalink
initial rule #1674
Browse files Browse the repository at this point in the history
  • Loading branch information
shunguoy committed Oct 13, 2023
1 parent 0e811d3 commit 41d127d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,32 @@ export class RPTUtil {
}
}

/**
* a target is en element that accept a pointer action (click or touch)
*/
public static isTarget(element) {
if (!element) return false;

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;

const parent = element.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;
}

public static tabIndexLEZero(elem) {
if (RPTUtil.hasAttribute(elem, "tabindex")) {
if (elem.getAttribute("tabindex").match(/^-?\d+$/)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
if (bnds.top <= bounds.top && bnds.left <= bounds.left && bnds.top + bnds.height >= bounds.top + bounds.height
&& bnds.left + bnds.height >= bounds.left + bounds.width
&& (before ? parseInt(zindex) < parseInt(z_index): parseInt(zindex) <= parseInt(z_index)))
// if the target is entirely covered: handled by element_tabbable_unobscured
// if the target is entirely covered: tabbable target handled by element_tabbable_unobscured and tabindex=-1 ignored
continue;

if (bnds.height !== 0 && bnds.width !== 0
Expand Down
2 changes: 1 addition & 1 deletion accessibility-checker-engine/src/v4/util/CommonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function getInvalidRoles(ruleContext: Element) {

let invalidRoles = [];

if (allowedRoles && allowedRoles.includes('any'))
if (allowedRoles.includes('any'))
return [];

for (let i = 0; i < domRoles.length; i++)
Expand Down

0 comments on commit 41d127d

Please sign in to comment.