diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts
index e9a17af85737..fb19d13f8746 100644
--- a/src/compiler/compile/nodes/Element.ts
+++ b/src/compiler/compile/nodes/Element.ts
@@ -616,17 +616,16 @@ export default class Element extends Node {
}
if (this.name === 'label') {
- const has_input_child = (children) => {
- const has_input = children.some(i => (i instanceof Element && a11y_labelable.has(i.name)));
- if (has_input) {
+ const has_input_child = (children: INode[]) => {
+ if (children.some(child => (child instanceof Element && (a11y_labelable.has(child.name) || child.name === 'slot')))) {
return true;
}
- for (const c of children) {
- if (!c.children || c.children.length === 0) {
+ for (const child of children) {
+ if (!('children' in child) || child.children.length === 0) {
continue;
}
- if (has_input_child(c.children)) {
+ if (has_input_child(child.children)) {
return true;
}
}
diff --git a/test/validator/samples/a11y-label-has-associated-control-2/input.svelte b/test/validator/samples/a11y-label-has-associated-control-2/input.svelte
new file mode 100644
index 000000000000..124888c089ad
--- /dev/null
+++ b/test/validator/samples/a11y-label-has-associated-control-2/input.svelte
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+G
diff --git a/test/validator/samples/a11y-label-has-associated-control-2/warnings.json b/test/validator/samples/a11y-label-has-associated-control-2/warnings.json
new file mode 100644
index 000000000000..fe51488c7066
--- /dev/null
+++ b/test/validator/samples/a11y-label-has-associated-control-2/warnings.json
@@ -0,0 +1 @@
+[]
diff --git a/test/validator/samples/a11y-label-has-associated-control/label.svelte b/test/validator/samples/a11y-label-has-associated-control/label.svelte
deleted file mode 100644
index de26d50782d1..000000000000
--- a/test/validator/samples/a11y-label-has-associated-control/label.svelte
+++ /dev/null
@@ -1,3 +0,0 @@
-