From cb70e5751bcb3bc6a8620a75958bfd9d69199733 Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Wed, 26 Feb 2025 15:27:32 -0600 Subject: [PATCH 1/2] failing test to demonstrate issue with restoring focus on a numeric id. --- test/restore-focus.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/restore-focus.js b/test/restore-focus.js index 4e76d4e..1c4a54a 100644 --- a/test/restore-focus.js +++ b/test/restore-focus.js @@ -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( + ` +
+ +
+ +
+
`, + ` +
+ + +
`, + "1", + "b", + ); + }); + it("preserves focus state when focused element is moved between anonymous containers", function () { assertFocusPreservationWithoutMoveBefore( ` From 88a02183d9caf10a2adc8da9b741dcb7c635518c Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Wed, 26 Feb 2025 15:30:15 -0600 Subject: [PATCH 2/2] fix error when trying to restore focus on an element with a numeric id. --- src/idiomorph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/idiomorph.js b/src/idiomorph.js index 8d62384..25d0ba7 100644 --- a/src/idiomorph.js +++ b/src/idiomorph.js @@ -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) {