-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
feat: add a11y autocomplete-valid
#8520
Changes from all commits
db072c3
c0b9cc1
1ab4085
d2dba32
ee6e889
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import { | |
} from 'aria-query'; | ||
import { AXObjects, AXObjectRoles, elementAXObjects } from 'axobject-query'; | ||
import Attribute from '../nodes/Attribute'; | ||
import { regex_whitespaces } from '../../utils/patterns'; | ||
|
||
const aria_roles = roles_map.keys(); | ||
const abstract_roles = new Set(aria_roles.filter(role => roles_map.get(role).abstract)); | ||
|
@@ -223,3 +224,104 @@ export function is_semantic_role_element(role: ARIARoleDefinitionKey, tag_name: | |
} | ||
return false; | ||
} | ||
|
||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute | ||
const address_type_tokens = new Set(['shipping', 'billing']); | ||
const autofill_field_name_tokens = new Set([ | ||
'', | ||
'on', | ||
'off', | ||
'name', | ||
'honorific-prefix', | ||
'given-name', | ||
'additional-name', | ||
'family-name', | ||
'honorific-suffix', | ||
'nickname', | ||
'username', | ||
'new-password', | ||
'current-password', | ||
'one-time-code', | ||
'organization-title', | ||
'organization', | ||
'street-address', | ||
'address-line1', | ||
'address-line2', | ||
'address-line3', | ||
'address-level4', | ||
'address-level3', | ||
'address-level2', | ||
'address-level1', | ||
'country', | ||
'country-name', | ||
'postal-code', | ||
'cc-name', | ||
'cc-given-name', | ||
'cc-additional-name', | ||
'cc-family-name', | ||
'cc-number', | ||
'cc-exp', | ||
'cc-exp-month', | ||
'cc-exp-year', | ||
'cc-csc', | ||
'cc-type', | ||
'transaction-currency', | ||
'transaction-amount', | ||
'language', | ||
'bday', | ||
'bday-day', | ||
'bday-month', | ||
'bday-year', | ||
'sex', | ||
'url', | ||
'photo' | ||
]); | ||
const contact_type_tokens = new Set(['home', 'work', 'mobile', 'fax', 'pager']); | ||
const autofill_contact_field_name_tokens = new Set([ | ||
'tel', | ||
'tel-country-code', | ||
'tel-national', | ||
'tel-area-code', | ||
'tel-local', | ||
'tel-local-prefix', | ||
'tel-local-suffix', | ||
'tel-extension', | ||
'email', | ||
'impp' | ||
]); | ||
|
||
export function is_valid_autocomplete(type: null | true | string, autocomplete: null | true | string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The types come from the inferred return type of |
||
if (typeof autocomplete !== 'string' || typeof type !== 'string') { | ||
return false; | ||
} | ||
|
||
const tokens = autocomplete.trim().toLowerCase().split(regex_whitespaces); | ||
|
||
if (typeof tokens[0] === 'string' && tokens[0].startsWith('section-')) { | ||
tokens.shift(); | ||
} | ||
|
||
if (address_type_tokens.has(tokens[0])) { | ||
tokens.shift(); | ||
} | ||
|
||
if (autofill_field_name_tokens.has(tokens[0])) { | ||
tokens.shift(); | ||
} else { | ||
if (contact_type_tokens.has(tokens[0])) { | ||
tokens.shift(); | ||
} | ||
|
||
if (autofill_contact_field_name_tokens.has(tokens[0])) { | ||
tokens.shift(); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
if (tokens[0] === 'webauthn') { | ||
tokens.shift(); | ||
} | ||
|
||
return tokens.length === 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!-- VALID --> | ||
<input type="text" /> | ||
<input type="text" autocomplete="name" /> | ||
<input type="text" autocomplete="off" /> | ||
<input type="text" autocomplete="on" /> | ||
<input type="text" autocomplete="billing family-name" /> | ||
<input type="hidden" autocomplete="section-blue shipping street-address" /> | ||
<input type="text" autocomplete="section-somewhere shipping work email" /> | ||
<input type="text" autocomplete="section-somewhere shipping work email webauthn" /> | ||
<input type="text" autocomplete="SECTION-SOMEWHERE SHIPPING WORK EMAIL WEBAUTHN" /> | ||
<input type="TEXT" autocomplete="ON" /> | ||
<input type="email" autocomplete="url" /> | ||
<input type="text" autocomplete="section-blue shipping street-address" /> | ||
<input type="hidden" autocomplete="off" /> | ||
<input type="hidden" autocomplete="on" /> | ||
<input type="text" autocomplete="" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say let's relax this then to allow the empty and boolean value. We also need a test that checks if it succeeds if a synamic value is given, like |
||
|
||
<!-- INVALID --> | ||
<input type="text" autocomplete /> | ||
<input type="text" autocomplete="incorrect" /> | ||
<input type="text" autocomplete="webauthn" /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[ | ||
{ | ||
"code": "a11y-autocomplete-valid", | ||
"end": { | ||
"column": 31, | ||
"line": 19 | ||
}, | ||
"message": "A11y: The value 'true' is not supported by the attribute 'autocomplete' on element <input type=\"text\">", | ||
"start": { | ||
"column": 19, | ||
"line": 19 | ||
} | ||
}, | ||
{ | ||
"code": "a11y-autocomplete-valid", | ||
"end": { | ||
"column": 43, | ||
"line": 20 | ||
}, | ||
"message": "A11y: The value 'incorrect' is not supported by the attribute 'autocomplete' on element <input type=\"text\">", | ||
"start": { | ||
"column": 19, | ||
"line": 20 | ||
} | ||
}, | ||
{ | ||
"code": "a11y-autocomplete-valid", | ||
"end": { | ||
"column": 42, | ||
"line": 21 | ||
}, | ||
"message": "A11y: The value 'webauthn' is not supported by the attribute 'autocomplete' on element <input type=\"text\">", | ||
"start": { | ||
"column": 19, | ||
"line": 21 | ||
} | ||
} | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not able to find any of the following tokens in either
axobject-query
oraria-query
.