Skip to content

Commit

Permalink
update the rule #1676
Browse files Browse the repository at this point in the history
  • Loading branch information
shunguoy committed Oct 5, 2023
1 parent 3d1ed98 commit 4767cca
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,21 @@ export class RPTUtil {
return walkNode;
}

/**
* return all the ancestor element names of the given element
* @param element
*/
public static getAncestorNames(element) {
if (!element) return null;
let ancestors = [];
let walkNode = DOMWalker.parentNode(element);
while (walkNode !== null) {
ancestors.push(walkNode.nodeName.toLowerCase());
walkNode = DOMWalker.parentNode(walkNode);
}
return ancestors;
}

// return true if element1 and element2 are siblings
public static isSibling(element1, element2) {
if (element1 && element2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export let aria_banner_single: Rule = {
}
},
rulesets: [{
"id": ["IBM_Accessibility", "WCAG_2_1", "WCAG_2_0"],
"id": ["IBM_Accessibility", "WCAG_2_1", "WCAG_2_0", "WCAG_2_2"],
"num": ["2.4.1"],
"level": eRulePolicy.VIOLATION,
"toolkitLevel": eToolkitLevel.LEVEL_THREE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,17 @@ export let element_tabbable_unobscured: Rule = {
if (!bounds) return null;

//ignore if offscreen
if (bounds['height'] === 0 || bounds['width'] === 0 || bounds['top'] < 0 || bounds['left'] < 0)
if (bounds['height'] === 0 || bounds['width'] === 0 )
return null;

let passed = true;
var elems = document.querySelectorAll('body *:not(' + nodeName +' *, ' + nodeName +')');
const ancestors = RPTUtil.getAncestorNames(ruleContext);
let ignoreList = nodeName +' *, ' + nodeName +', script';
if (ancestors) {
ancestors.forEach(ancestor=> {
ignoreList += ", " + ancestor;
});
}
var elems = ruleContext.ownerDocument.querySelectorAll('body *:not(' + ignoreList +')'); console.log("select target=" + nodeName + ", elems="+elems.length);
if (!elems || elems.length == 0)
return;

Expand All @@ -73,15 +79,17 @@ export let element_tabbable_unobscured: Rule = {
elems.forEach(elem => {
// Skip hidden
if (VisUtil.isNodeVisible(elem)) {
const bnds = mapper.getBounds(elem);
if (bnds.top <= bounds.top && bnds.left <= bounds.left && bnds.top + bnds.height >= bounds.top + bounds.height
&& bnds.top + bnds.height >= bounds.left + bounds.width)
violations.push(elem);
const bnds = mapper.getBounds(elem); console.log("target=" + nodeName + ", current=" + elem.nodeName + ", bounds=" + JSON.stringify(bounds) +", bnds=" + JSON.stringify(bnds));
if (bnds.height !== 0 && bnds.width !== 0
&& bnds.top <= bounds.top && bnds.left <= bounds.left && bnds.top + bnds.height >= bounds.top + bounds.height
&& bnds.left + bnds.height >= bounds.left + bounds.width) {
violations.push(elem); console.log("hit target=" + nodeName + ", current=" + elem.nodeName + ", bounds=" + JSON.stringify(bounds) +", bnds=" + JSON.stringify(bnds));
}
}
});

if (violations.length > 0)
return RulePotential("potential_visible", []);
return RulePotential("potential_obscured", []);

return RulePass("pass");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export let input_label_before: Rule = {
}
},
rulesets: [{
"id": ["IBM_Accessibility", "WCAG_2_1", "WCAG_2_0"],
"id": ["IBM_Accessibility", "WCAG_2_1", "WCAG_2_0", "WCAG_2_2"],
"num": ["3.3.2"],
"level": eRulePolicy.VIOLATION,
"toolkitLevel": eToolkitLevel.LEVEL_ONE
Expand Down

0 comments on commit 4767cca

Please sign in to comment.