Skip to content

Commit b6288ec

Browse files
authored
fix: Handle dynamic values in a11y-autocomplete-valid (#8567)
Fixes #8562 Fixes #8565
1 parent 4537eb7 commit b6288ec

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Svelte changelog
22

3+
## 3.59.1 (Unreleased)
4+
5+
* Handle dynamic values in `a11y-autocomplete-valid` ([#8567](https://github.com/sveltejs/svelte/pull/8567))
6+
37
## 3.59.0
48

59
* Add `ResizeObserver` bindings `contentRect`/`contentBoxSize`/`borderBoxSize`/`devicePixelContentBoxSize` ([#8022](https://github.com/sveltejs/svelte/pull/8022))

src/compiler/compile/compiler_warnings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export default {
164164
}),
165165
a11y_autocomplete_valid: (type: null | true | string, value: null | true | string) => ({
166166
code: 'a11y-autocomplete-valid',
167-
message: `A11y: The value '${value}' is not supported by the attribute 'autocomplete' on element <input type="${type}">`
167+
message: `A11y: The value '${value}' is not supported by the attribute 'autocomplete' on element <input type="${type || '...'}">`
168168
}),
169169
a11y_img_redundant_alt: {
170170
code: 'a11y-img-redundant-alt',

src/compiler/compile/nodes/Element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ export default class Element extends Node {
857857
const type_value = type.get_static_value();
858858
const autocomplete_value = autocomplete.get_static_value();
859859

860-
if (!is_valid_autocomplete(type_value, autocomplete_value)) {
860+
if (!is_valid_autocomplete(autocomplete_value)) {
861861
component.warn(autocomplete, compiler_warnings.a11y_autocomplete_valid(type_value, autocomplete_value));
862862
}
863863
}

src/compiler/compile/utils/a11y.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,11 @@ const autofill_contact_field_name_tokens = new Set([
290290
'impp'
291291
]);
292292

293-
export function is_valid_autocomplete(type: null | true | string, autocomplete: null | true | string) {
294-
if (typeof autocomplete !== 'string' || typeof type !== 'string') {
293+
export function is_valid_autocomplete(autocomplete: null | true | string) {
294+
if (autocomplete === true) {
295295
return false;
296+
} else if (!autocomplete) {
297+
return true; // dynamic value
296298
}
297299

298300
const tokens = autocomplete.trim().toLowerCase().split(regex_whitespaces);

test/validator/samples/a11y-autocomplete-valid/input.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<script>
2+
let dynamic = '';
3+
</script>
4+
15
<!-- VALID -->
26
<input type="text" />
37
<input type="text" autocomplete="name" />
@@ -14,6 +18,8 @@
1418
<input type="hidden" autocomplete="off" />
1519
<input type="hidden" autocomplete="on" />
1620
<input type="text" autocomplete="" />
21+
<input type="{dynamic}" autocomplete="" />
22+
<input type="text" autocomplete="{dynamic}" />
1723

1824
<!-- INVALID -->
1925
<input type="text" autocomplete />

test/validator/samples/a11y-autocomplete-valid/warnings.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,36 @@
33
"code": "a11y-autocomplete-valid",
44
"end": {
55
"column": 31,
6-
"line": 19
6+
"line": 25
77
},
88
"message": "A11y: The value 'true' is not supported by the attribute 'autocomplete' on element <input type=\"text\">",
99
"start": {
1010
"column": 19,
11-
"line": 19
11+
"line": 25
1212
}
1313
},
1414
{
1515
"code": "a11y-autocomplete-valid",
1616
"end": {
1717
"column": 43,
18-
"line": 20
18+
"line": 26
1919
},
2020
"message": "A11y: The value 'incorrect' is not supported by the attribute 'autocomplete' on element <input type=\"text\">",
2121
"start": {
2222
"column": 19,
23-
"line": 20
23+
"line": 26
2424
}
2525
},
2626
{
2727
"code": "a11y-autocomplete-valid",
2828
"end": {
2929
"column": 42,
30-
"line": 21
30+
"line": 27
3131
},
3232
"message": "A11y: The value 'webauthn' is not supported by the attribute 'autocomplete' on element <input type=\"text\">",
3333
"start": {
3434
"column": 19,
35-
"line": 21
35+
"line": 27
3636
}
3737
}
3838
]

0 commit comments

Comments
 (0)