-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
autofocus is not working on input rerender in Chrome and Firefox #15261
Comments
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus
https://html.spec.whatwg.org/multipage/interaction.html#the-autofocus-attribute I think what you're seeing is expected behavior. It would be more annoying if an element with |
This does not happen with plain HTML & JS in any browser, including Safari. There is an This probably needs additional logic to check for first render or the popover/dialog case. |
@brunnerh you mean the correct thing would be to fix Safari here? |
No, as noted, Safari seems to behave the same as other browsers for plain HTML/JS (i.e. not focusing on inserting new elements with Some test code<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Auto-Focus</title>
</head>
<body>
<button>click</button>
<input type="text" placeholder="0" autofocus>
<script>
let i = 0;
const button = document.querySelector('button');
button.addEventListener('click', () => {
button.nextElementSibling?.remove();
i++;
const input = document.createElement('input');
input.autofocus = true;
input.type = 'text';
input.placeholder = i.toString();
document.body.insertBefore(input, button.nextElementSibling);
});
</script>
</body>
</html> I propose changing Svelte's Looking at the function I did not see anything that would cause it: svelte/packages/svelte/src/internal/client/dom/elements/misc.js Lines 10 to 21 in 02788f8
But upon adding a line testing for the // added at end of click handler:
queueMicrotask(() => console.log(document.activeElement)); Edit: Apparently this is for consistency with Mac software in general, the behavior is noted on MDN.
|
Should I close this ticket then, since the behavior I am experiencing isn't a bug? |
There arguably is a bug, just a different one. |
Describe the bug
If you have an input and then rerender your view with another autofocused input, then autofocus does not seem to work. I see this bug in Chrome and Firefox, but in Safari it seems to work fine.
Reproduction
Just click button multiple times in this REPL.
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: