Skip to content

Text input focus sometimes lost on rerender/error #150

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

Closed
henrikvilhelmberglund opened this issue Dec 15, 2022 · 1 comment · Fixed by #161
Closed

Text input focus sometimes lost on rerender/error #150

henrikvilhelmberglund opened this issue Dec 15, 2022 · 1 comment · Fixed by #161
Labels
bug Something isn't working

Comments

@henrikvilhelmberglund
Copy link

Just typing I find the text input focus is lost randomly which makes typing difficult. The following gif is from https://learn.svelte.dev/tutorial/your-first-component

focus

This seems like a problem because I'm writing the script tag and end tag before the contents of it, is that something I shouldn't do?

@dummdidumm dummdidumm added the bug Something isn't working label Dec 15, 2022
@dummdidumm
Copy link
Member

dummdidumm commented Dec 16, 2022

I believe it's SvelteKit's "reset focus" action which causes this. It will only happen for tutorials that have export const ssr = false (so, all Svelte tutorials and some SvelteKit tutorials), because only in that case the initial navigation is played, which in the end resets the focus. Not sure yet how to best counteract it (doing addEventListener and preventDefault doesn't seem to help). One possible way - if we can't prevent the focus action itself - could be to refocus the text editor (there are methods for doing that, and also for getting/setting the cursor position, in case that's needed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants