Skip to content

Commit

Permalink
fix(router): prevent loop of focus events on multiple dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Apr 3, 2024
1 parent dda4f91 commit c51c6c0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ function setupView(hybrids, routerOptions, parent, nestedParent) {

if (options.dialog) {
connects.add((host) => {
const root = rootRouter;

const goBackOnEscKey = (event) => {
if (event.key === "Escape") {
event.stopPropagation();
Expand All @@ -290,13 +292,17 @@ function setupView(hybrids, routerOptions, parent, nestedParent) {
};

const focusDialog = (event) => {
if (!host.contains(event.target) && event.target !== host) {
const stack = stacks.get(root);

if (
stack[stack.length - 1] === host &&
!host.contains(event.target) &&
event.target !== host
) {
focusElement(host);
}
};

const root = rootRouter;

root.addEventListener("focusin", focusDialog);
root.addEventListener("focusout", focusDialog);
host.addEventListener("keydown", goBackOnEscKey);
Expand Down

0 comments on commit c51c6c0

Please sign in to comment.