Skip to content

Commit ed7d92a

Browse files
committed
[fix] omit a11y warning for native checkbox/radio inputs
Fixes sveltejs#7837
1 parent ed078e3 commit ed7d92a

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
@@ -515,6 +515,12 @@ export default class Element extends Node {
515515
const has_missing_props = required_role_props.some(prop => !attributes.find(a => a.name === prop));
516516

517517
if (has_missing_props) {
518+
// native checkbox/radio inputs do not require ARIA attributes
519+
if (this.name === 'input') {
520+
const type = attributes.find((a) => a.name === 'type').get_static_value();
521+
if (type === 'checkbox' || type === 'radio') return;
522+
}
523+
518524
component.warn(attribute, compiler_warnings.a11y_role_has_required_aria_props(value as string, required_role_props));
519525
}
520526
}

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)