Skip to content

Commit 941c79a

Browse files
committed
only suggest default value for boolean/tristate attributes
1 parent dea9033 commit 941c79a

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

packages/svelte/messages/compile-warnings/a11y.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626

2727
> Avoid `<%name%>` elements
2828
29+
## a11y_empty_aria_attribute
30+
31+
> '%attribute%' cannot be empty
32+
33+
> '%attribute%' cannot be empty — change it to `%attribute%="%value%"`
34+
2935
## a11y_figcaption_index
3036

3137
> `<figcaption>` must be first or last child of `<figure>`
@@ -46,10 +52,6 @@
4652

4753
> The value of '%attribute%' must be of type %type%
4854
49-
## a11y_empty_aria_attribute
50-
51-
> '%attribute%' cannot be empty — change it to `%attribute%="true"`
52-
5355
## a11y_incorrect_aria_attribute_type_boolean
5456

5557
> The value of '%attribute%' must be either 'true' or 'false'

packages/svelte/src/compiler/phases/2-analyze/a11y.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,8 @@ function validate_aria_attribute_value(attribute, name, schema, value) {
605605
if (value === null) return;
606606

607607
if (value === true) {
608-
w.a11y_empty_aria_attribute(attribute, name);
608+
const v = type === 'boolean' || type === 'tristate' ? 'true' : undefined;
609+
w.a11y_empty_aria_attribute(attribute, name, v);
609610
return;
610611
}
611612

packages/svelte/src/compiler/warnings.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ export function a11y_distracting_elements(node, name) {
100100
w(node, "a11y_distracting_elements", `Avoid \`<${name}>\` elements`);
101101
}
102102

103+
/**
104+
* '%attribute%' cannot be empty — change it to `%attribute%="%value%"`
105+
* @param {null | NodeLike} node
106+
* @param {string} attribute
107+
* @param {string | undefined | null} [value]
108+
*/
109+
export function a11y_empty_aria_attribute(node, attribute, value) {
110+
w(node, "a11y_empty_aria_attribute", value ? `'${attribute}' cannot be empty — change it to \`${attribute}="${value}"\`` : `'${attribute}' cannot be empty`);
111+
}
112+
103113
/**
104114
* `<figcaption>` must be first or last child of `<figure>`
105115
* @param {null | NodeLike} node
@@ -143,15 +153,6 @@ export function a11y_incorrect_aria_attribute_type(node, attribute, type) {
143153
w(node, "a11y_incorrect_aria_attribute_type", `The value of '${attribute}' must be of type ${type}`);
144154
}
145155

146-
/**
147-
* '%attribute%' cannot be empty — change it to `%attribute%="true"`
148-
* @param {null | NodeLike} node
149-
* @param {string} attribute
150-
*/
151-
export function a11y_empty_aria_attribute(node, attribute) {
152-
w(node, "a11y_empty_aria_attribute", `'${attribute}' cannot be empty — change it to \`${attribute}="true"\``);
153-
}
154-
155156
/**
156157
* The value of '%attribute%' must be either 'true' or 'false'
157158
* @param {null | NodeLike} node

packages/svelte/tests/validator/samples/a11y-aria-proptypes-integer/warnings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
{
2727
"code": "a11y_empty_aria_attribute",
28-
"message": "'aria-level' cannot be empty — change it to `aria-level=\"true\"`",
28+
"message": "'aria-level' cannot be empty",
2929
"start": {
3030
"line": 4,
3131
"column": 5

0 commit comments

Comments
 (0)