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

Autocomplete bug fixes #46

Merged
merged 2 commits into from
May 17, 2024
Merged
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
5 changes: 3 additions & 2 deletions lib/checks/forms/autocomplete-a11y-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isValidAutocomplete } from "../../commons/text";
function checkIsElementValidAutocomplete(node, options, virtualNode) {
const autocomplete = virtualNode.attr('autocomplete')?.toLowerCase().trim();
// if element has autocomplete attribute as off then it is not a violation
if(autocomplete === "off") {
if(autocomplete === "off" || autocomplete==="chrome-off") {
return true;
}

Expand Down Expand Up @@ -33,7 +33,8 @@ function checkIsElementValidAutocomplete(node, options, virtualNode) {
const closestForm = virtualNode.actualNode.closest("form");

//if it exists inside the form and autocomplete for form is off
if(closestForm && closestForm.getAttribute('autocomplete')?.toLowerCase().trim() === "off") {
if(closestForm && (closestForm.getAttribute('autocomplete')?.toLowerCase().trim() === "off"
|| closestForm.getAttribute('autocomplete')?.toLowerCase().trim() === "chrome-off")) {
// if autocomplete attribute is not present for element then its a pass in this scenario
// otherwise check all posibilities with the method
return autocomplete ? checkIsElementValidAutocomplete(node, options, virtualNode) : true;
Expand Down
4 changes: 2 additions & 2 deletions lib/checks/forms/autocomplete-valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"id": "autocomplete-valid",
"evaluate": "autocomplete-a11y-evaluate",
"metadata": {
"impact": "serious",
"impact": "moderate",
"messages": {
"pass": "the autocomplete attribute is correctly formatted",
"fail": "the autocomplete attribute is incorrectly formatted"
"fail": "Add autocomplete attribute to form fields with a valid value as per HTML specification. In 'name' attribute of field, prefer to use standard autocomplete value since browsers use 'name' to suggest autofill. For field with no standard autocomplete value (eg: College ID), prefer to use autocomplete='on'."
}
},
"options": {
Expand Down
15 changes: 12 additions & 3 deletions lib/rules/autocomplete-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { sanitize } from '../commons/text';
import standards from '../standards';
import { isVisible } from '../commons/dom';

function autocompleteMatches(node, virtualNode, flag=false) {
function autocompleteMatches(node, virtualNode, flag = false) {
const autocomplete = virtualNode.attr('autocomplete');
if ((!autocomplete || sanitize(autocomplete) === '') && !flag) {
return false;
Expand All @@ -13,8 +13,17 @@ function autocompleteMatches(node, virtualNode, flag=false) {
return false;
}

// The element is an `input` element a `type` of `hidden`, `button`, `submit` or `reset`
const excludedInputTypes = ['submit', 'reset', 'button', 'hidden'];
// The element is an `input` element a `type` of `hidden`, `reset`,`button`, `submit` , 'checkbox', 'file', 'image', or 'radio'
const excludedInputTypes = [
'submit',
'reset',
'button',
'hidden',
'checkbox',
'file',
'image',
'radio'
];
if (
nodeName === 'input' &&
excludedInputTypes.includes(virtualNode.props.type)
Expand Down
13 changes: 10 additions & 3 deletions lib/rules/autocomplete-valid.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
{
"id": "autocomplete-valid",
"matches": "autocomplete-a11y-matches",
"tags": ["cat.forms", "wcag21aa", "wcag135"],
"tags": [
"cat.forms",
"wcag21aa",
"wcag22aa",
"wcag135",
"a11y-engine",
"a11y-engine-experimental"
],
"actIds": ["73f2c2"],
"metadata": {
"description": "Ensure the autocomplete attribute is correct and suitable for the form field",
"help": "autocomplete attribute must be used correctly"
"description": "Ensure that the necessary form fields use the autocomplete attribute with a valid input.",
"help": "Autocomplete attribute must have a valid value"
},
"all": ["autocomplete-valid"],
"any": [],
Expand Down