Skip to content

Commit 5cfac19

Browse files
wackbyteRich-Harris
authored andcommitted
fix: prevent a11y_label_has_associated_control false positive for component in <label> (sveltejs#12119)
* fix: prevent `a11y_label_has_associated_control` false positive for component in `<label>` * fix render tags as well * Update .changeset/swift-rats-sing.md --------- Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Rich Harris <[email protected]>
1 parent 0dc6afe commit 5cfac19

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

.changeset/swift-rats-sing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: prevent `a11y_label_has_associated_control` false positive for component or render tag in `<label>`

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,8 @@ function check_element(node, state) {
10861086
if (
10871087
node.type === 'SvelteElement' ||
10881088
node.type === 'SlotElement' ||
1089+
node.type === 'Component' ||
1090+
node.type === 'RenderTag' ||
10891091
(node.type === 'RegularElement' &&
10901092
(a11y_labelable.includes(node.name) || node.name === 'slot'))
10911093
) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
<script>
2+
import Component from './component.svelte'
3+
</script>
4+
15
<label>
26
<slot />
37
</label>
8+
9+
<label>
10+
<Component />
11+
</label>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
import Component from './component.svelte'
3+
</script>
4+
5+
<label>
6+
{@render x()}
7+
</label>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

0 commit comments

Comments
 (0)