Preserve focus across node replacements

This commit is contained in:
Tony Garnock-Jones 2023-12-01 23:56:32 +01:00
parent b013dd1979
commit 3445f3f014
1 changed files with 6 additions and 0 deletions

View File

@ -57,7 +57,13 @@ export class Widget implements EventTarget {
}
}
const wasFocus = oldNode && document.activeElement === oldNode;
oldNode?.parentNode?.replaceChild(newNode, oldNode);
if (wasFocus) {
if (newNode && newNode instanceof HTMLElement) {
newNode.focus();
}
}
this.node.value = newNode;
}