Closed ciscoheat closed 1 month ago
Current workaround:
$effect(() => {
if ($errors.amount) {
setTimeout(() => document.querySelector('input[name="amount"]')?.focus());
}
});
Can you reproduce this with Svelte 4? I'm not able to. Or does the same thing happen with a regular (non-component) input?
You're on the money about usually using a tick()
or otherwise, but it seems like in this case waiting for the state to update via $effect()
then focusing would work but it shouldn't have to be like that.
True, I cannot reproduce it on Svelte 4 either. But it works with a regular input even on Svelte 5.
I could post an issue at the Svelte repo, but maybe a dependency on both Superforms and shadcn-svelte won't be appreciated. :)
We could just recreate an <Input />
component and use it with only Superforms to isolate the issue further before bringing it to their attention!
I think I managed to reproduce it without any of the libs, will post an issue at Svelte.
Nope, it was harder than I thought.
So you can't reproduce by creating an <Input />
component and using it in place of the one for shadcn-svelte? All it does is wrap a regular input.
Gonna close this as I haven't been able to reproduce and from my understanding it shouldn't be an issue with this lib as it's just rendering an HTML input :)
Describe the bug
As you certainly know, Superforms has an autoFocusOnError option, enabled as default, focusing on an error field when the form is submitted. I noticed that the Input component doesn't always get focus.
I've been debugging Superforms, changing the wait time before focusing from the current
await tick()
to setTimeout with 100 ms delay, but nothing seems to work, so I don't think it's a Superforms issue.Reproduction
https://github.com/ciscoheat/shadcn-svelte-not-focusing
Instructions are included there.
Logs
No response
System Info
Severity
annoyance