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
2 changes: 1 addition & 1 deletion src/idiomorph.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ var Idiomorph = (function () {
const results = fn();

if (activeElementId && activeElementId !== document.activeElement?.id) {
activeElement = ctx.target.querySelector(`#${activeElementId}`);
activeElement = ctx.target.querySelector(`[id="${activeElementId}"]`);
activeElement?.focus();
}
if (activeElement && !activeElement.selectionEnd && selectionEnd) {
Expand Down
19 changes: 19 additions & 0 deletions test/restore-focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,25 @@ describe("Option to forcibly restore focus after morph", function () {
assertFocus("focused");
});

it("restores focus state with reparented numeric id", function () {
assertFocusPreservationWithoutMoveBefore(
`
<div>
<input type="text" id="other">
<div>
<input type="text" id="1" value="abc">
</div>
</div>`,
`
<div>
<input type="text" id="other">
<input type="text" id="1" value="abc">
</div>`,
"1",
"b",
);
});

it("preserves focus state when focused element is moved between anonymous containers", function () {
assertFocusPreservationWithoutMoveBefore(
`
Expand Down