Skip to content

Commit b23e6ce

Browse files
metonymtanhauhau
authored andcommitted
[fix] omit a11y warning for native checkbox/radio inputs
Fixes sveltejs#7837
1 parent d7cfe22 commit b23e6ce

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/compiler/compile/nodes/Element.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,12 @@ export default class Element extends Node {
520520
const has_missing_props = required_role_props.some(prop => !attributes.find(a => a.name === prop));
521521

522522
if (has_missing_props) {
523+
// native checkbox/radio inputs do not require ARIA attributes
524+
if (this.name === 'input') {
525+
const type = attributes.find((a) => a.name === 'type').get_static_value();
526+
if (type === 'checkbox' || type === 'radio') return;
527+
}
528+
523529
component.warn(attribute, compiler_warnings.a11y_role_has_required_aria_props(value as string, required_role_props));
524530
}
525531
}

test/validator/samples/a11y-role-has-required-aria-props/input.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
<span role="checkbox" aria-checked="false"></span>
88
<div role="meter" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
99
<div role="scrollbar" aria-controls="panel" aria-valuenow="50"></div>
10+
<input role="switch" type="checkbox" />
11+
<input role="switch" type="radio" />

0 commit comments

Comments
 (0)