Preserve focus across node replacements
This commit is contained in:
parent
b013dd1979
commit
3445f3f014
|
@ -57,7 +57,13 @@ export class Widget implements EventTarget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const wasFocus = oldNode && document.activeElement === oldNode;
|
||||||
oldNode?.parentNode?.replaceChild(newNode, oldNode);
|
oldNode?.parentNode?.replaceChild(newNode, oldNode);
|
||||||
|
if (wasFocus) {
|
||||||
|
if (newNode && newNode instanceof HTMLElement) {
|
||||||
|
newNode.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.node.value = newNode;
|
this.node.value = newNode;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue