File tree Expand file tree Collapse file tree 5 files changed +58
-32
lines changed
src/compiler/compile/nodes
a11y-label-has-associated-control-2
a11y-label-has-associated-control Expand file tree Collapse file tree 5 files changed +58
-32
lines changed Original file line number Diff line number Diff line change @@ -626,8 +626,24 @@ export default class Element extends Node {
626626 }
627627
628628 if ( this . name === 'label' ) {
629- const has_input_child = this . children . some ( i => ( i instanceof Element && a11y_labelable . has ( i . name ) ) ) ;
630- if ( ! attribute_map . has ( 'for' ) && ! has_input_child ) {
629+ const has_input_child = ( children : INode [ ] ) => {
630+ if ( children . some ( child => ( child instanceof Element && ( a11y_labelable . has ( child . name ) || child . name === 'slot' ) ) ) ) {
631+ return true ;
632+ }
633+
634+ for ( const child of children ) {
635+ if ( ! ( 'children' in child ) || child . children . length === 0 ) {
636+ continue ;
637+ }
638+ if ( has_input_child ( child . children ) ) {
639+ return true ;
640+ }
641+ }
642+
643+ return false ;
644+ } ;
645+
646+ if ( ! attribute_map . has ( 'for' ) && ! has_input_child ( this . children ) ) {
631647 component . warn ( this , compiler_warnings . a11y_label_has_associated_control ) ;
632648 }
633649 }
Original file line number Diff line number Diff line change 1+ <label >
2+ <slot />
3+ </label >
Original file line number Diff line number Diff line change 1+ []
Original file line number Diff line number Diff line change 1+ <script >
2+ import LabelComponent from ' ./label.svelte'
3+ </script >
4+
15<label >A</label >
26<label for =" id" >B</label >
37
48<label >C <input type =" text" /></label >
59<label >D <button >D</button ></label >
610<label >E <span ></span ></label >
11+ <label >F {#if true }<input type ="text" />{/if }</label >
12+ <LabelComponent >G <input type =" text" /></LabelComponent >
Original file line number Diff line number Diff line change 11[
2- {
3- "code" : " a11y-label-has-associated-control" ,
4- "end" : {
5- "character" : 16 ,
6- "column" : 16 ,
7- "line" : 1
8- },
9- "message" : " A11y: A form label must be associated with a control." ,
10- "pos" : 0 ,
11- "start" : {
12- "character" : 0 ,
13- "column" : 0 ,
14- "line" : 1
15- }
16- },
17- {
18- "code" : " a11y-label-has-associated-control" ,
19- "end" : {
20- "character" : 149 ,
21- "column" : 30 ,
22- "line" : 6
23- },
24- "message" : " A11y: A form label must be associated with a control." ,
25- "pos" : 119 ,
26- "start" : {
27- "character" : 119 ,
28- "column" : 0 ,
29- "line" : 6
30- }
31- }
2+ {
3+ "code" : " a11y-label-has-associated-control" ,
4+ "end" : {
5+ "character" : 82 ,
6+ "column" : 16 ,
7+ "line" : 5
8+ },
9+ "message" : " A11y: A form label must be associated with a control." ,
10+ "pos" : 66 ,
11+ "start" : {
12+ "character" : 66 ,
13+ "column" : 0 ,
14+ "line" : 5
15+ }
16+ },
17+ {
18+ "code" : " a11y-label-has-associated-control" ,
19+ "end" : {
20+ "character" : 215 ,
21+ "column" : 30 ,
22+ "line" : 10
23+ },
24+ "message" : " A11y: A form label must be associated with a control." ,
25+ "pos" : 185 ,
26+ "start" : {
27+ "character" : 185 ,
28+ "column" : 0 ,
29+ "line" : 10
30+ }
31+ }
3232]
You can’t perform that action at this time.
0 commit comments