1- import { isValidAutocomplete } from "../../commons/text" ;
1+ import { isValidAutocomplete } from '../../commons/text' ;
2+ import { ErrorHandler } from '../../../../a11y-engine-core/lib/core/errors/error-handler' ;
23
34function checkIsElementValidAutocomplete ( node , options , virtualNode ) {
4- const autocomplete = virtualNode . attr ( 'autocomplete' ) ?. toLowerCase ( ) . trim ( ) ;
5- // if element has autocomplete attribute as off then it is not a violation
6- if ( autocomplete === "off" || autocomplete === "chrome-off" ) {
7- return true ;
8- }
9-
10- // if it is on then we check whether name / id have valid autocomplete value or not
11- // same for the case if autocomplete is not present or has a non-standard value
12- if ( ! autocomplete || autocomplete === "on" || ! isValidAutocomplete ( autocomplete , options ) ) {
13- const name = virtualNode . attr ( 'name' ) ;
14- const id = virtualNode . attr ( 'id' ) ;
15- if ( ( name && isValidAutocomplete ( name , options ) ) || ( id && isValidAutocomplete ( id , options ) ) )
16- return true ;
17- return false ;
18- }
19-
20- // if element autocomplete attribute is neither off nor on then we check if its a standard value
21- if ( isValidAutocomplete ( autocomplete , options ) ) {
5+ const autocomplete = virtualNode
6+ . attr ( 'autocomplete' )
7+ ?. toLowerCase ( )
8+ . trim ( ) ;
9+ // if element has autocomplete attribute as off then it is not a violation
10+ if ( autocomplete === 'off' || autocomplete === 'chrome-off' ) {
11+ return true ;
12+ }
13+
14+ // if it is on then we check whether name / id have valid autocomplete value or not
15+ // same for the case if autocomplete is not present or has a non-standard value
16+ if (
17+ ! autocomplete ||
18+ autocomplete === 'on' ||
19+ ! isValidAutocomplete ( autocomplete , options )
20+ ) {
21+ const name = virtualNode . attr ( 'name' ) ;
22+ const id = virtualNode . attr ( 'id' ) ;
23+ if (
24+ ( name && isValidAutocomplete ( name , options ) ) ||
25+ ( id && isValidAutocomplete ( id , options ) )
26+ ) {
2227 return true ;
2328 }
24-
2529 return false ;
2630 }
27-
28- function autocompleteA11yEvaluate ( node , options , virtualNode ) {
29- try {
30- const autocomplete = virtualNode . attr ( 'autocomplete' ) ;
31-
32- // check if the autocomplete applicable element is inside form or exist freely
33- const closestForm = virtualNode . actualNode . closest ( "form" ) ;
34-
35- //if it exists inside the form and autocomplete for form is off
36- if ( closestForm && ( closestForm . getAttribute ( 'autocomplete' ) ?. toLowerCase ( ) . trim ( ) === "off"
37- || closestForm . getAttribute ( 'autocomplete' ) ?. toLowerCase ( ) . trim ( ) === "chrome-off" ) ) {
38- // if autocomplete attribute is not present for element then its a pass in this scenario
39- // otherwise check all posibilities with the method
40- return autocomplete ? checkIsElementValidAutocomplete ( node , options , virtualNode ) : true ;
41- } else {
42- // The else case is if form is present and it has autocomplete as on or not set and
43- // the other case this handles is that element exists independently
44-
45- // this method would check for all posibilities
46- return checkIsElementValidAutocomplete ( node , options , virtualNode ) ;
47- }
48- }
49- catch ( err ) {
50- ErrorHandler . addCheckError ( "autocomplete-attribute-valid-check" , err ) ;
51- return undefined ;
31+
32+ // if element autocomplete attribute is neither off nor on then we check if its a standard value
33+ if ( isValidAutocomplete ( autocomplete , options ) ) {
34+ return true ;
35+ }
36+
37+ return false ;
38+ }
39+
40+ function autocompleteA11yEvaluate ( node , options , virtualNode ) {
41+ try {
42+ const autocomplete = virtualNode . attr ( 'autocomplete' ) ;
43+
44+ // check if the autocomplete applicable element is inside form or exist freely
45+ const closestForm = virtualNode . actualNode . closest ( 'form' ) ;
46+
47+ //if it exists inside the form and autocomplete for form is off
48+ if (
49+ closestForm &&
50+ ( closestForm
51+ . getAttribute ( 'autocomplete' )
52+ ?. toLowerCase ( )
53+ . trim ( ) === 'off' ||
54+ closestForm
55+ . getAttribute ( 'autocomplete' )
56+ ?. toLowerCase ( )
57+ . trim ( ) === 'chrome-off' )
58+ ) {
59+ // if autocomplete attribute is not present for element then its a pass in this scenario
60+ // otherwise check all posibilities with the method
61+ return autocomplete
62+ ? checkIsElementValidAutocomplete ( node , options , virtualNode )
63+ : true ;
64+ } else {
65+ // The else case is if form is present and it has autocomplete as on or not set and
66+ // the other case this handles is that element exists independently
67+
68+ // this method would check for all posibilities
69+ return checkIsElementValidAutocomplete ( node , options , virtualNode ) ;
5270 }
71+ } catch ( err ) {
72+ ErrorHandler . addCheckError ( 'autocomplete-attribute-valid-check' , err ) ;
73+ return undefined ;
5374 }
54-
55- export default autocompleteA11yEvaluate ;
75+ }
76+
77+ export default autocompleteA11yEvaluate ;
0 commit comments