Skip to content
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
19 changes: 19 additions & 0 deletions lib/rules/autocomplete-a11y-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,32 @@ function isCombobox(node) {
return node.getAttribute('role') === 'combobox';
}

// [a11y-rule-autocomplete-valid]: these input types sit in no HTML autofill control group, so no WCAG 1.3.5 input purpose applies; only judge them when the author set autocomplete
const UNAUTOFILLABLE_INPUT_TYPES = [
'range',
'color',
'week',
'time',
'datetime-local'
];

function isUnautofillableTypeWithoutAutocomplete(virtualNode) {
const autocomplete = virtualNode.attr('autocomplete');
return (
virtualNode.props.nodeName === 'input' &&
UNAUTOFILLABLE_INPUT_TYPES.includes(virtualNode.props.type) &&
(!autocomplete || autocomplete.trim() === '')
);
}

function autocompleteA11yMatches(node, virtualNode) {
const a11yEngineFlag = true;
/* the flag is used to tell autocomplete matcher that it is being called
by a11y-engine and thus bypass an if block
The second condition is to check we are not matching with search functionality */
return (
autocompleteMatches(node, virtualNode, a11yEngineFlag) &&
!isUnautofillableTypeWithoutAutocomplete(virtualNode) &&
!nodeIsASearchFunctionality(node) &&
!quantityField(node) &&
!isReadOnly(node) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,10 @@
<!-- When readonly attributes placed, should be ignored -->
<input autocomplete="badterm" readonly id="inapplicable11" />
<input autocomplete="badterm" aria-readonly="true" id="inapplicable12" />

<!-- Types in no autofill group, without an authored autocomplete, are ignored -->
<input type="range" aria-label="Hours" id="inapplicable13" />
<input type="color" aria-label="Theme" id="inapplicable14" />
<input type="week" aria-label="Week" id="inapplicable15" />
<input type="time" aria-label="Start" id="inapplicable16" />
<input type="datetime-local" aria-label="Departure" id="inapplicable17" />
67 changes: 67 additions & 0 deletions test/rule-matches/autocomplete-a11y-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,71 @@ describe('autocomplete-a11y-matches', () => {
// The label text "Search" marks the field as search, so it is not matched.
assert.isFalse(rule.matches(vNode.actualNode, vNode));
});

describe('input types that cannot collect user information', () => {
it('returns false for a range slider without autocomplete', () => {
const vNode = queryFixture(
'<input id="target" type="range" min="1" max="23" aria-label="Layover hours">'
);
assert.isFalse(rule.matches(vNode.actualNode, vNode));
});

it('returns false for a colour picker without autocomplete', () => {
const vNode = queryFixture(
'<input id="target" type="color" aria-label="Theme colour">'
);
assert.isFalse(rule.matches(vNode.actualNode, vNode));
});

['week', 'time', 'datetime-local'].forEach(type => {
it(`returns false for input[type=${type}] without autocomplete`, () => {
const vNode = queryFixture(
`<input id="target" type="${type}" aria-label="Departure">`
);
assert.isFalse(rule.matches(vNode.actualNode, vNode));
});
});

it('treats an upper-case type and a blank autocomplete as unset', () => {
const vNode = queryFixture(
'<input id="target" type="RANGE" autocomplete=" " aria-label="Price">'
);
assert.isFalse(rule.matches(vNode.actualNode, vNode));
});

it('still returns true for a colour picker with autocomplete="off"', () => {
const vNode = queryFixture(
'<input id="target" type="color" autocomplete="off" aria-label="Theme colour">'
);
assert.isTrue(rule.matches(vNode.actualNode, vNode));
});

it('still returns true for a range slider with an authored autocomplete', () => {
const vNode = queryFixture(
'<input id="target" type="range" autocomplete="email" aria-label="Amount">'
);
assert.isTrue(rule.matches(vNode.actualNode, vNode));
});

it('still returns true for a text field without autocomplete', () => {
const vNode = queryFixture(
'<input id="target" type="text" aria-label="Full name">'
);
assert.isTrue(rule.matches(vNode.actualNode, vNode));
});

it('still returns true for a date field without autocomplete', () => {
const vNode = queryFixture(
'<input id="target" type="date" aria-label="Date of birth">'
);
assert.isTrue(rule.matches(vNode.actualNode, vNode));
});

it('still returns true for an unknown type, which renders as a text field', () => {
const vNode = queryFixture(
'<input id="target" type="slider" aria-label="Amount">'
);
assert.isTrue(rule.matches(vNode.actualNode, vNode));
});
});
});
Loading