Skip to content

Commit 9e15546

Browse files
authored
Merge pull request #3332 from Conduitry/gh-3331
fix erroneous a11y warning with input type='image'
2 parents 6cbdd9b + 276eb8e commit 9e15546

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/compiler/compile/nodes/Element.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,12 @@ export default class Element extends Node {
451451
if (this.name === 'input') {
452452
const type = attribute_map.get('type');
453453
if (type && type.get_static_value() === 'image') {
454-
should_have_attribute(
455-
this,
456-
['alt', 'aria-label', 'aria-labelledby'],
457-
'input type="image"'
458-
);
454+
const required_attributes = ['alt', 'aria-label', 'aria-labelledby'];
455+
const has_attribute = required_attributes.some(name => attribute_map.has(name));
456+
457+
if (!has_attribute) {
458+
should_have_attribute(this, required_attributes, 'input type="image"');
459+
}
459460
}
460461
}
461462
}

test/validator/samples/a11y-alt-text/input.svelte

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66

77
<object></object>
88

9-
<input type='image'>
9+
<input type='image'>
10+
11+
<input type='image' alt='hey'>

0 commit comments

Comments
 (0)