Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/healthy-poets-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: correctly applies autofocus to static elements
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ export function RegularElement(node, context) {
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);
if (
binding !== null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ function is_static_element(node) {
return false;
}

if (attribute.name === 'autofocus') {
return false;
}

if (node.name === 'option' && attribute.name === 'value') {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from '../../test';

export default test({
async test({ assert, target, window }) {
assert.equal(target.querySelector('input'), window.document.activeElement);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>wat</h1>
<input autofocus />
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from '../../test';

export default test({
async test({ assert, target, window }) {
assert.equal(target.querySelector('input'), window.document.activeElement);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
<input autofocus />
</div>