fix: correctly applies autofocus to static elements (#13648)

* fix: correctly applies autofocus to static elements

* lint

* fix other case
pull/13640/head
Dominic Gannaway 11 months ago committed by GitHub
parent e21e624fff
commit 193cc37f7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: correctly applies autofocus to static elements

@ -75,6 +75,14 @@ export function RegularElement(node, context) {
node.attributes.push(create_attribute('value', child.start, child.end, [child])); node.attributes.push(create_attribute('value', child.start, child.end, [child]));
} }
if (
node.attributes.some(
(attribute) => attribute.type === 'Attribute' && attribute.name === 'autofocus'
)
) {
mark_subtree_dynamic(context.path);
}
const binding = context.state.scope.get(node.name); const binding = context.state.scope.get(node.name);
if ( if (
binding !== null && binding !== null &&

@ -142,6 +142,10 @@ function is_static_element(node) {
return false; return false;
} }
if (attribute.name === 'autofocus') {
return false;
}
if (node.name === 'option' && attribute.name === 'value') { if (node.name === 'option' && attribute.name === 'value') {
return false; return false;
} }

@ -0,0 +1,7 @@
import { test } from '../../test';
export default test({
async test({ assert, target, window }) {
assert.equal(target.querySelector('input'), window.document.activeElement);
}
});

@ -0,0 +1,7 @@
import { test } from '../../test';
export default test({
async test({ assert, target, window }) {
assert.equal(target.querySelector('input'), window.document.activeElement);
}
});
Loading…
Cancel
Save