Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(engine): update the isTabbable method for radio groups #2201

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ export const widget_tabbable_single: Rule = {
while (count < 2 && nw.nextNode() && nw.node != ruleContext) {
if (nw.node.nodeType == 1 && !nw.bEndTag && CommonUtil.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') {
/**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;
}
}
Expand Down
27 changes: 26 additions & 1 deletion accessibility-checker-engine/src/v4/util/CommonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,32 @@ export class CommonUtil {
},
"iframe": true,
"input": function (element): boolean {
return element.getAttribute("type") !== "hidden" && !element.hasAttribute("disabled");
if (element.hasAttribute("disabled") || element.getAttribute("type") === "hidden") return false;
if (element.getAttribute("type") === "radio") {
const name = element.getAttribute("name");
if (!name || name.trim().length === 0) return true; //single radio, no group
let doc = element.ownerDocument;
const group = doc.querySelectorAll("input[type='radio'][name='" + name.trim() +"']");
if (group.length === 0 || group.length === 1) return true; //single radio with the name, no others in group

let checked = null;
for (let i = 0; i < group.length; i++) {
if ((group[i] as HTMLInputElement).checked)
checked = group[i];
}
//only last one applies if multiple radios with 'checked' attributes
if (checked !== null) {
if (DOMUtil.sameNode(checked, element))
return true;
return false;
} else {
// if nothing checked yet, return true if it's the first element
if (DOMUtil.sameNode(group[0], element))
return true;
return false;
}
} else
return true;
},
"select": function (element): boolean {
return !element.hasAttribute("disabled");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
<!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>
<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
<fieldset role="radiogroup">
<label><input name="rChk" type="radio">One</label><br/>
<label><input name="rChk" type="radio">Two</label><br/>
<label><input name="rChk" type="radio">Three</label><br/>
<label><input name="rChk" type="radio">Four</label><br/>
</fieldset>

<fieldset role="radiogroup">
<label><input name="rChk2" type="radio">One</label><br/>
<label><input name="rChk2" type="radio">Two</label><br/>
<label><input name="rChk2" type="radio">Three</label><br/>
<label><input name="rChk2" type="radio" checked>Four</label><br/>
</fieldset>

<fieldset role="radiogroup">
<label><input name="rChk3" type="radio" checked>One</label><br/>
<label><input name="rChk3" type="radio">Two</label><br/>
<label><input name="rChk3" type="radio">Three</label><br/>
<label><input name="rChk3" type="radio" checked>Four</label><br/>
</fieldset>

<script type="text/javascript">
UnitTest = {
ruleIds: ["widget_tabbable_single"],
results: [
{
"ruleId": "widget_tabbable_single",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/fieldset[1]",
"aria": "/document[1]/radiogroup[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]/fieldset[1]/label[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]/fieldset[1]/label[2]/input[1]",
"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]/fieldset[1]/label[3]/input[1]",
"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]/fieldset[1]/label[4]/input[1]",
"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]/fieldset[2]",
"aria": "/document[1]/radiogroup[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]/fieldset[2]/label[1]/input[1]",
"aria": "/document[1]/radiogroup[2]/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]/fieldset[2]/label[2]/input[1]",
"aria": "/document[1]/radiogroup[2]/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]/fieldset[2]/label[3]/input[1]",
"aria": "/document[1]/radiogroup[2]/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]/fieldset[2]/label[4]/input[1]",
"aria": "/document[1]/radiogroup[2]/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]/fieldset[3]",
"aria": "/document[1]/radiogroup[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]/fieldset[3]/label[1]/input[1]",
"aria": "/document[1]/radiogroup[3]/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]/fieldset[3]/label[2]/input[1]",
"aria": "/document[1]/radiogroup[3]/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]/fieldset[3]/label[3]/input[1]",
"aria": "/document[1]/radiogroup[3]/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]/fieldset[3]/label[4]/input[1]",
"aria": "/document[1]/radiogroup[3]/radio[4]"
},
"reasonId": "pass",
"message": "Components with a widget role should have no more than one tabbable element",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
}
],
};
</script>
</body>
</html>