Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

svelte(a11y-label-has-associated-control) shows incorrectly when using render snippet #11711

Open
ViincentLim opened this issue May 21, 2024 · 4 comments

Comments

@ViincentLim
Copy link

Describe the bug

The warning A form label must be associated with a control(a11y_label_has_associated_control)(svelte/valid-compile shows up even when the label has a render children inside.

<label>
	<span>{label}</span>
	{@render children?.()}
</label>

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAEz2O3WrDMAyFX0WIQVsI672b_uwNBrusd5ElSmdwZCOrhWH87sPOujvp45yPk3F2nhKaa0YeFkKDbzFih_oT65Me5JWwwxTuMlbSp1FcVPAD344WNVk8WbbqlhhEofYgwwe7GEmhwCxhgc3q2RwstywryTyMBO8SYoJcoVU_fJE3kFQc37qVjd_OT0J8Nk9n5WX1eFLI0GodPJNQzJ_2CC-xHtvdwXK_X4fXsdy3TtvdpzjwKTdQ-n37Ks8XIZ5I_r3n1-2uVM_axQ6XMLnZ0YRG5U7ls_wCoGD20E4BAAA=

<script lang="ts">
	import type { Snippet } from 'svelte';

	interface Props {
		label: string,
		children?: Snippet
	}

	let { label, children }: Props = $props();
</script>

<label>
	<span>{label}</span>
	{@render children?.()}
</label>

Logs

No response

System Info

"svelte": "5.0.0-next.136",
"svelte-eslint-parser": "^0.36.0",
"@sveltejs/kit": "^2.5.9",

Severity

annoyance

@ViincentLim
Copy link
Author

Would be nice to define element tag as well

@paoloricciuti
Copy link
Member

Yeah but you can't know what the render tag will render...it might render an input, a div or even nothing.

@Conduitry
Copy link
Member

The only thing the compiler could do here is to silence all such warnings that might be false positives because of the {@render}. I'm not too happy with that idea. I'd probably just say you should put a <!-- svelte-ignore --> comment in if you're sure this isn't a problem.

@paoloricciuti
Copy link
Member

Yeah the compiler should not make assumptions imho...you can have assumptions since you know your code. And you can even avoid the warning by using a for attribute (this again if you are sure about your code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants