Skip to content
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

fix: correctly interpret empty aria- attribute #11325

Merged
merged 7 commits into from
Apr 25, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/brown-geckos-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: correctly interpret empty aria- attribute
4 changes: 2 additions & 2 deletions packages/svelte/messages/compile-warnings/a11y.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@

## a11y_incorrect_aria_attribute_type

> The value of '%attribute%' must be of type %type%
> The value of '%attribute%' must be a %type%

## a11y_incorrect_aria_attribute_type_boolean

> The value of '%attribute%' must be either 'true' or 'false'
> The value of '%attribute%' must be either 'true' or 'false'. It cannot be empty

## a11y_incorrect_aria_attribute_type_id

Expand Down
15 changes: 7 additions & 8 deletions packages/svelte/src/compiler/phases/2-analyze/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function has_disabled_attribute(attribute_map) {
const aria_disabled_attr = attribute_map.get('aria-disabled');
if (aria_disabled_attr) {
const aria_disabled_attr_value = get_static_value(aria_disabled_attr);
if (aria_disabled_attr_value === true) {
if (aria_disabled_attr_value === 'true') {
return true;
}
}
Expand Down Expand Up @@ -601,20 +601,19 @@ function is_parent(parent, elements) {
*/
function validate_aria_attribute_value(attribute, name, schema, value) {
const type = schema.type;
const is_string = typeof value === 'string';

if (value === null) return;
if (value === true) value = 'true'; // TODO this is actually incorrect, and we should fix it
if (value === true) value = '';

if (type === 'boolean' && value !== 'true' && value !== 'false') {
w.a11y_incorrect_aria_attribute_type_boolean(attribute, name);
} else if (type === 'integer' && !Number.isInteger(+value)) {
} else if (type === 'integer' && (value === '' || !Number.isInteger(+value))) {
w.a11y_incorrect_aria_attribute_type_integer(attribute, name);
} else if (type === 'number' && isNaN(+value)) {
} else if (type === 'number' && (value === '' || isNaN(+value))) {
w.a11y_incorrect_aria_attribute_type(attribute, name, 'number');
} else if ((type === 'string' || type === 'id') && !is_string) {
w.a11y_incorrect_aria_attribute_type(attribute, name, 'string');
} else if (type === 'idlist' && !is_string) {
} else if ((type === 'string' || type === 'id') && value === '') {
w.a11y_incorrect_aria_attribute_type(attribute, name, 'non-empty string');
} else if (type === 'idlist' && value === '') {
w.a11y_incorrect_aria_attribute_type_idlist(attribute, name);
} else if (type === 'token') {
const values = (schema.values ?? []).map((value) => value.toString());
Expand Down
8 changes: 4 additions & 4 deletions packages/svelte/src/compiler/warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,22 @@ export function a11y_img_redundant_alt(node) {
}

/**
* The value of '%attribute%' must be of type %type%
* The value of '%attribute%' must be a %type%
* @param {null | NodeLike} node
* @param {string} attribute
* @param {string} type
*/
export function a11y_incorrect_aria_attribute_type(node, attribute, type) {
w(node, "a11y_incorrect_aria_attribute_type", `The value of '${attribute}' must be of type ${type}`);
w(node, "a11y_incorrect_aria_attribute_type", `The value of '${attribute}' must be a ${type}`);
}

/**
* The value of '%attribute%' must be either 'true' or 'false'
* The value of '%attribute%' must be either 'true' or 'false'. It cannot be empty
* @param {null | NodeLike} node
* @param {string} attribute
*/
export function a11y_incorrect_aria_attribute_type_boolean(node, attribute) {
w(node, "a11y_incorrect_aria_attribute_type_boolean", `The value of '${attribute}' must be either 'true' or 'false'`);
w(node, "a11y_incorrect_aria_attribute_type_boolean", `The value of '${attribute}' must be either 'true' or 'false'. It cannot be empty`);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"code": "a11y_incorrect_aria_attribute_type_boolean",
"message": "The value of 'aria-disabled' must be either 'true' or 'false'",
"message": "The value of 'aria-disabled' must be either 'true' or 'false'. It cannot be empty",
"start": {
"line": 5,
"column": 8
Expand All @@ -13,7 +13,7 @@
},
{
"code": "a11y_incorrect_aria_attribute_type_boolean",
"message": "The value of 'aria-disabled' must be either 'true' or 'false'",
"message": "The value of 'aria-disabled' must be either 'true' or 'false'. It cannot be empty",
"start": {
"line": 6,
"column": 8
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div aria-level="yes"></div>
<div aria-level="no"></div>
<div aria-level={`abc`}></div>
<div aria-level={true}></div>
<div aria-level></div>
<div aria-level={"false"}></div>
<div aria-level={!"false"}></div>
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
"code": "a11y_incorrect_aria_attribute_type_integer",
"message": "The value of 'aria-level' must be an integer",
"start": {
"line": 5,
"line": 4,
"column": 5
},
"end": {
"line": 5,
"line": 4,
"column": 15
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<div aria-valuemax="no"></div>
<div aria-valuemax={`abc`}></div>
<div aria-valuemax={true}></div>
<div aria-valuemax></div>
<div aria-valuemax="true"></div>
<div aria-valuemax={'false'}></div>
<div aria-valuemax={!'false'}></div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"code": "a11y_incorrect_aria_attribute_type",
"message": "The value of 'aria-valuemax' must be of type number",
"message": "The value of 'aria-valuemax' must be a number",
"start": {
"line": 1,
"column": 5
Expand All @@ -13,7 +13,7 @@
},
{
"code": "a11y_incorrect_aria_attribute_type",
"message": "The value of 'aria-valuemax' must be of type number",
"message": "The value of 'aria-valuemax' must be a number",
"start": {
"line": 2,
"column": 5
Expand All @@ -25,14 +25,14 @@
},
{
"code": "a11y_incorrect_aria_attribute_type",
"message": "The value of 'aria-valuemax' must be of type number",
"message": "The value of 'aria-valuemax' must be a number",
"start": {
"line": 5,
"column": 5
},
"end": {
"line": 5,
"column": 18
"column": 25
}
}
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div aria-label></div>
<div aria-label="true"></div>
<div aria-label={true}></div>
<div aria-label={false}></div>
<div aria-label={1234}></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
[
{
"code": "a11y_incorrect_aria_attribute_type",
"message": "The value of 'aria-label' must be of type string",
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 15
}
}
]
[]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div aria-sort=""></div>
<div aria-sort="incorrect"></div>
<div aria-sort></div>
<div aria-sort="true"></div>
<div aria-sort={true}></div>
<div aria-sort={"false"}></div>
<div aria-sort="ascending descending"></div>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"end": {
"line": 3,
"column": 14
"column": 21
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div aria-relevant=""></div>
<div aria-relevant="foobar"></div>
<div aria-relevant></div>
<div aria-relevant="true"></div>
<div aria-relevant={true}></div>
<div aria-relevant={"false"}></div>
<div aria-relevant="additions removals_"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"end": {
"line": 3,
"column": 18
"column": 25
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<input on:click={noop} type="hidden" />

<!-- svelte-ignore a11y_no_static_element_interactions -->
<div on:click={noop} aria-hidden></div>
<div on:click={noop} aria-hidden="true"></div>
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div on:click={noop} aria-hidden="true"></div>
<!-- svelte-ignore a11y_no_static_element_interactions -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h1></h1>
<h2 aria-hidden>invisible header</h2>
<h2 aria-hidden="true">invisible header</h2>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"end": {
"line": 2,
"column": 15
"column": 22
}
}
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<img src="foo" alt="Foo eating a sandwich." />
<img src="bar" aria-hidden alt="Picture of me taking a photo of an image" />
<img src="bar" aria-hidden="true" alt="Picture of me taking a photo of an image" />
<img src="foo" alt="Photo of foo being weird." />
<img src="bar" alt="Image of me at a bar!" />
<img src="foo" alt="Picture of baz fixing a bug." />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- VALID -->
<div aria-hidden role="button" on:keypress={() => {}}></div>
<div aria-disabled role="button" on:keypress={() => {}}></div>
<div aria-hidden="true" role="button" on:keypress={() => {}}></div>
<div aria-disabled="true" role="button" on:keypress={() => {}}></div>
<div disabled role="button" on:keypress={() => {}}></div>
<div role="presentation" on:keypress={() => {}}></div>
<button on:click={() => {}}></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
<video></video>
<video><track /></video>
<audio></audio>
<video aria-hidden></video>
<video aria-hidden="false"></video>
<video aria-hidden="true"></video>
<video aria-hidden="false"></video>
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@
"line": 3
}
},
{
"code": "a11y_media_has_caption",
"end": {
"column": 27,
"line": 5
},
"message": "`<video>` elements must have a `<track kind=\"captions\">`",
"start": {
"column": 0,
"line": 5
}
},
{
"code": "a11y_media_has_caption",
"end": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@
<div role="menu"></div>
<div role="menubar"></div>
<div role="menuitem"></div>
<div role="menuitemcheckbox" aria-checked></div>
<div role="menuitemradio" aria-checked></div>
<div role="option" aria-selected></div>
<div role="menuitemcheckbox" aria-checked="true"></div>
<div role="menuitemradio" aria-checked="true"></div>
<div role="option" aria-selected="true"></div>
<div role="progressbar"></div>
<div role="radio" aria-checked></div>
<div role="radio" aria-checked="true"></div>
<div role="radiogroup"></div>
<div role="row"></div>
<div role="rowheader"></div>
<div role="scrollbar" aria-controls={[]} aria-valuenow={0}></div>
<div role="searchbox"></div>
<div role="slider" aria-valuenow={0}></div>
<div role="spinbutton"></div>
<div role="switch" aria-checked></div>
<div role="switch" aria-checked="true"></div>
<div role="tab"></div>
<div role="textbox"></div>
<div role="treeitem" aria-selected={true}></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- VALID -->
<div role="presentation" on:mouseup={() => {}}></div>
<div role="button" tabindex="-1" on:click={() => {}} on:keypress={() => {}}></div>
<div role="listitem" aria-hidden on:click={() => {}} on:keypress={() => {}}></div>
<div role="listitem" aria-hidden="true" on:click={() => {}} on:keypress={() => {}}></div>
<button on:click={() => {}}></button>
<h1 contenteditable="true" on:keydown={() => {}}>Heading</h1>
<h1>Heading</h1>
Expand Down
Loading
Loading