Skip to content

Commit

Permalink
Merge pull request #1913 from IBMa/dev-1649
Browse files Browse the repository at this point in the history
fixrule(`widget_tabbable_single`):  Radio inputs in the same group should have only one tab stop
  • Loading branch information
ErickRenteria authored Jun 3, 2024
2 parents 7954dcd + eca9aa6 commit dc4aed3
Showing 9 changed files with 894 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -24,21 +24,21 @@ export let widget_tabbable_single: Rule = {
refactor: {
"IBMA_Focus_MultiTab": {
"pass": "pass",
"fail_multiple_tabbable": "fail_multiple_tabbable"
"potential_multiple_tabbable": "potential_multiple_tabbable"
}
},
help: {
"en-US": {
"pass": "widget_tabbable_single.html",
"fail_multiple_tabbable": "widget_tabbable_single.html",
"potential_multiple_tabbable": "widget_tabbable_single.html",
"group": "widget_tabbable_single.html"
}
},
messages: {
"en-US": {
"pass": "Rule Passed",
"fail_multiple_tabbable": "Component with \"{0}\" role has more than one tabbable element",
"group": "Certain components must have no more than one tabbable element"
"pass": "Components with a widget role should have no more than one tabbable element",
"potential_multiple_tabbable": "Component with \"{0}\" role has more than one tabbable element",
"group": "Components with a widget role must have no more than one tabbable element"
}
},
rulesets: [{
@@ -66,17 +66,26 @@ export let widget_tabbable_single: Rule = {
}
// If node has children, look for tab stops in the children
//skip the count if the element requires presentational children only
let name = [];
if (count < 2 && !RPTUtil.containsPresentationalChildrenOnly(ruleContext) && ruleContext.firstChild) {
let nw = new NodeWalker(ruleContext);
while (count < 2 && nw.nextNode() && nw.node != ruleContext) {
if (nw.node.nodeType == 1 && !nw.bEndTag && RPTUtil.isTabbable(nw.node)) {
// Radio inputs with the same name natively are only one tab stop
if (nw.node.nodeName.toLowerCase() === 'input' && (nw.node as Element).getAttribute("type") === 'radio') {
let curName = (nw.node as Element).getAttribute("name");
if (name.includes(curName))
continue;
else
name.push(curName);
}
++count;
}
}
}
let passed = count < 2;
if (!passed)
setCache(ruleContext, "widget_tabbable_single", "fail_multiple_tabbable");
return passed ? RulePass("pass") : RulePotential("fail_multiple_tabbable", [role]);
setCache(ruleContext, "widget_tabbable_single", "potential_multiple_tabbable");
return passed ? RulePass("pass") : RulePotential("potential_multiple_tabbable", [role]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
/******************************************************************************
Copyright:: 2020- IBM, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*****************************************************************************/
-->

<html lang="en">

<head>

<title>RPT Test Suite</title>

</head>

<body>

<label>Main content</a>

<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->

<h1>Display Radio Buttons</h1>

<fieldset role="radiogroup" aria-labelledby="desc">
<legend id="desc">select your age and favorite pet</legend>
<input type="radio" id="age1" name="age" value="30">
<label for="age1">0 - 30</label><br>
<input type="radio" id="age2" name="age" value="60">
<label for="age2">31 - 60</label><br>
<input type="radio" id="age3" name="age" value="100">
<label for="age3">61 - 100</label><br><br>

<input type="radio" id="pet1" name="pet" value="dog" >
<label for="pet1">Dog</label><br>
<input type="radio" id="pet2" name="pet" value="cat">
<label for="pet2">Cat</label><br>
<input type="radio" id="pet3" name="pet" value="other" >
<label for="pet3">Other</label><br><br>

<input type="radio" id="fruit1" value="apple" >
<label for="fruit1">Apple</label><br>
<input type="radio" id="fruit2" value="pear" >
<label for="fruit2">Pear</label><br>
<input type="radio" id="fruit3" value="banana" >
<label for="fruit3">Banana</label><br><br>
</div>

<script type="text/javascript">
UnitTest = {
ruleIds: ["widget_tabbable_single"],
results: [
{
"ruleId": "widget_tabbable_single",
"value": [
"INFORMATION",
"POTENTIAL"
],
"path": {
"dom": "/html[1]/body[1]/label[1]/fieldset[1]",
"aria": "/document[1]/radiogroup[1]"
},
"reasonId": "potential_multiple_tabbable",
"message": "Component with \"radiogroup\" role has more than one tabbable element",
"messageArgs": [
"radiogroup"
],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "widget_tabbable_single",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/label[1]/fieldset[1]/input[1]",
"aria": "/document[1]/radiogroup[1]/radio[1]"
},
"reasonId": "pass",
"message": "Components with a widget role should have no more than one tabbable element",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "widget_tabbable_single",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/label[1]/fieldset[1]/input[2]",
"aria": "/document[1]/radiogroup[1]/radio[2]"
},
"reasonId": "pass",
"message": "Components with a widget role should have no more than one tabbable element",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "widget_tabbable_single",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/label[1]/fieldset[1]/input[3]",
"aria": "/document[1]/radiogroup[1]/radio[3]"
},
"reasonId": "pass",
"message": "Components with a widget role should have no more than one tabbable element",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "widget_tabbable_single",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/label[1]/fieldset[1]/input[4]",
"aria": "/document[1]/radiogroup[1]/radio[4]"
},
"reasonId": "pass",
"message": "Components with a widget role should have no more than one tabbable element",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "widget_tabbable_single",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/label[1]/fieldset[1]/input[5]",
"aria": "/document[1]/radiogroup[1]/radio[5]"
},
"reasonId": "pass",
"message": "Components with a widget role should have no more than one tabbable element",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "widget_tabbable_single",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/label[1]/fieldset[1]/input[6]",
"aria": "/document[1]/radiogroup[1]/radio[6]"
},
"reasonId": "pass",
"message": "Components with a widget role should have no more than one tabbable element",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "widget_tabbable_single",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/label[1]/fieldset[1]/input[7]",
"aria": "/document[1]/radiogroup[1]/radio[7]"
},
"reasonId": "pass",
"message": "Components with a widget role should have no more than one tabbable element",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "widget_tabbable_single",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/label[1]/fieldset[1]/input[8]",
"aria": "/document[1]/radiogroup[1]/radio[8]"
},
"reasonId": "pass",
"message": "Components with a widget role should have no more than one tabbable element",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "widget_tabbable_single",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/label[1]/fieldset[1]/input[9]",
"aria": "/document[1]/radiogroup[1]/radio[9]"
},
"reasonId": "pass",
"message": "Components with a widget role should have no more than one tabbable element",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
}
]
}
</script></body>
</html>
Loading

0 comments on commit dc4aed3

Please sign in to comment.