Skip to content

Commit

Permalink
update spaing rule #1974
Browse files Browse the repository at this point in the history
  • Loading branch information
shunguoy committed Oct 28, 2024
1 parent c51b995 commit 796c3a8
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 18 deletions.
26 changes: 26 additions & 0 deletions accessibility-checker-engine/src/v4/util/AriaUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,32 @@ export class AriaUtil {
return roles;
}

/**
* return the roles with given role type.
*
* @parm {element} element - The element to start the node walk on to find parent node
* @parm {array} roleTyples - role types, such as 'widget', 'structure' etc.
*
* @return {array} roles - A parent node of the element passed in, which has the provided role
*
* @memberOf AriaUtil
*/
public static isWidget(element) {
if (!element) return false;

const widget = CacheUtil.getCache(element.ownerDocument, "is_element_widget", null);
if (widget === null) {
let ret = false;
const role = AriaUtil.getResolvedRole(element);
if (role && ARIADefinitions.designPatterns[role].roleType === 'widget')
ret = true;

CacheUtil.setCache(element.ownerDocument, "is_element_widget", ret);
return ret;
}
return widget;
}

/**
* This function is responsible for finding a node which matches the role and is a sibling of the
* provided element.
Expand Down
34 changes: 29 additions & 5 deletions accessibility-checker-engine/src/v4/util/CommonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export class CommonUtil {
return !element.hasAttribute("disabled");
},
"textarea": true,
"div": function (element) {
/**"div": function (element) {
return element.hasAttribute("contenteditable");
},
},*/
"a": function (element) {
// xlink:href?? see svg
return element.hasAttribute("href");
Expand Down Expand Up @@ -109,6 +109,7 @@ export class CommonUtil {
}
return retVal;
} else {
if (element.hasAttribute("contenteditable")) return true;
return false;
}
}
Expand All @@ -123,6 +124,29 @@ export class CommonUtil {
return CommonUtil.isTabbable(ele);
}

/**
* Note that this only detects if the element itself is interactive, but not onclick event.
*/
public static isClickable(element) {
if (!VisUtil.isNodeVisible(element)) return false;

// native focusable element
let nodeName = element.nodeName.toLowerCase();
if (nodeName in CommonUtil.tabTagMap) {
let retVal = CommonUtil.tabTagMap[nodeName];
if (typeof (retVal) === "function") {
retVal = retVal(element);
}
return retVal;
} else {
//custom widget
if (AriaUtil.isWidget(element) && element.hasAttribute("tabindex")) {
return true;
}
}
return false;
}

/*
* get conflict Aria and Html attributes
* return: a list of Aria and Html attribute pairs that are conflict
Expand Down Expand Up @@ -457,15 +481,15 @@ export class CommonUtil {
* a target is en element that accept a pointer action (click or touch)
*
*/
public static isTarget(element) {
public static isTarget(element) {
if (!element || element.nodeType !== 1
|| ["html", "body"].includes(element.nodeName.toLowerCase())
|| CommonUtil.getAncestor(element, ["svg", "pre", "code", "script", "meta", 'head']) !== null
|| !VisUtil.isNodeVisible(element) || VisUtil.isNodeVisuallyHidden(element)
|| CommonUtil.isNodeDisabled(element) || VisUtil.isElementOffscreen(element))
return false;

if (element.hasAttribute("tabindex") || CommonUtil.isTabbable(element))
if (CommonUtil.isClickable(element))
return true;

const role = AriaUtil.getResolvedRole(element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@

<body>

<div id="first" tabindex="0">1</div>
<div id="second" tabindex="0">2</div>
<div role='button' id="first" tabindex="0">1</div>
<div role='button' id="second" tabindex="0">2</div>

<script>
UnitTest = {
Expand All @@ -67,7 +67,7 @@
],
"path": {
"dom": "/html[1]/body[1]/div[2]",
"aria": "/document[1]"
"aria": "/document[1]/button[2]"
},
"reasonId": "pass_sized",
"message": "The target’s size is more than 24 CSS pixels",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@

<body>

<div id="first" tabindex="0">1</div>
<div id="second" tabindex="0">2</div>
<div role='button' id="first" tabindex="0">1</div>
<div role='button' id="second" tabindex="0">2</div>

<script>
UnitTest = {
Expand All @@ -69,7 +69,7 @@
],
"path": {
"dom": "/html[1]/body[1]/div[2]",
"aria": "/document[1]"
"aria": "/document[1]/button[2]"
},
"reasonId": "pass_sized",
"message": "The target’s size is more than 24 CSS pixels",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@

<body>

<div id="first" tabindex="0">1</div>
<div id="second" tabindex="0">2</div>
<div role='button' id="first" tabindex="0">1</div>
<div role='button' id="second" tabindex="0">2</div>

<script>
UnitTest = {
Expand All @@ -69,7 +69,7 @@
],
"path": {
"dom": "/html[1]/body[1]/div[1]",
"aria": "/document[1]"
"aria": "/document[1]/button[1]"
},
"reasonId": "pass_sized",
"message": "The target’s size is more than 24 CSS pixels",
Expand All @@ -85,7 +85,7 @@
],
"path": {
"dom": "/html[1]/body[1]/div[2]",
"aria": "/document[1]"
"aria": "/document[1]/button[2]"
},
"reasonId": "potential_overlap",
"message": "Ensure the overlapped target \"div\" meets a minimum target size or has sufficient spacing from the overlapping target \"div\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@

<body>

<div id="first" tabindex="0">1</div>
<div id="second" tabindex="0">2</div>
<div role='button' id="first" tabindex="0">1</div>
<div role='button' id="second" tabindex="0">2</div>

<script>
UnitTest = {
Expand All @@ -69,7 +69,7 @@
],
"path": {
"dom": "/html[1]/body[1]/div[2]",
"aria": "/document[1]"
"aria": "/document[1]/button[2]"
},
"reasonId": "pass_sized",
"message": "The target’s size is more than 24 CSS pixels",
Expand Down

0 comments on commit 796c3a8

Please sign in to comment.