pre init focused elements keep the focus after init

This commit is contained in:
Rene Haas
2022-08-08 20:41:39 +02:00
parent 185c000c5a
commit 7cdc6e1c8f
14 changed files with 196 additions and 181 deletions
@@ -129,8 +129,8 @@ export const createStructureSetupElements = (
);
const viewportIsTarget = viewportElement === targetElement;
const viewportIsTargetBody = viewportIsTarget && isBody;
const setFocus =
!viewportIsTarget && wnd.top === wnd && ownerDocument.activeElement === targetElement;
const activeElm = ownerDocument.activeElement;
const setViewportFocus = !viewportIsTarget && wnd.top === wnd && activeElm === targetElement;
const evaluatedTargetObj: StructureSetupElementsObj = {
_target: targetElement,
_host: isTextarea
@@ -241,7 +241,7 @@ export const createStructureSetupElements = (
insertBefore(_viewport, _viewportArrange);
push(destroyFns, removeElements.bind(0, _viewportArrange));
}
if (setFocus) {
if (setViewportFocus) {
const ogTabindex = attr(_viewport, tabIndexStr);
attr(_viewport, tabIndexStr, '-1');
@@ -251,6 +251,8 @@ export const createStructureSetupElements = (
ogTabindex ? attr(_viewport, tabIndexStr, ogTabindex) : removeAttr(_viewport, tabIndexStr);
off();
});
} else if (activeElm && (activeElm as HTMLElement).focus) {
(activeElm as HTMLElement).focus();
}
// @ts-ignore