diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index ce4f1f4e..99c51998 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [8.2.22](https://github.com/hybridsjs/hybrids/compare/v8.2.21...v8.2.22) (2024-04-23) + ### [8.2.21](https://github.com/hybridsjs/hybrids/compare/v8.2.20...v8.2.21) (2024-04-19) diff --git a/package-lock.json b/package-lock.json index 3cd6507c..feb95b11 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "hybrids", - "version": "8.2.21", + "version": "8.2.22", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "hybrids", - "version": "8.2.21", + "version": "8.2.22", "license": "MIT", "bin": { "hybrids": "cli/index.js" diff --git a/package.json b/package.json index e2689df6..d62518a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hybrids", - "version": "8.2.21", + "version": "8.2.22", "description": "A JavaScript framework for creating fully-featured web applications, components libraries, and single web components with unique declarative and functional architecture", "type": "module", "exports": { diff --git a/src/router.js b/src/router.js index ef8df03f..066e1092 100644 --- a/src/router.js +++ b/src/router.js @@ -19,8 +19,12 @@ function setDebug(value = true) { const scrollMap = new WeakMap(); const focusMap = new WeakMap(); -function saveLayout(target) { +function saveLayout() { + const target = stacks.get(rootRouter)[0]; + if (!target) return; + const focusEl = globalThis.document.activeElement; + focusMap.set(target, rootRouter.contains(focusEl) && focusEl); const map = new Map(); @@ -285,7 +289,9 @@ function setupView(hybrids, routerOptions, parent, nestedParent) { const root = rootRouter; const goBackOnEscKey = (event) => { - if (event.key === "Escape") { + const stack = stacks.get(root); + + if (stack[0] === host && event.key === "Escape") { event.stopPropagation(); globalThis.history.go(-1); } @@ -957,6 +963,7 @@ function connectRootRouter(host, invalidate, options) { globalThis.history.go(-offset); } else { + saveLayout(); replace(); } } @@ -976,8 +983,7 @@ function connectRootRouter(host, invalidate, options) { if (offset > -1) { navigateBack(offset, entry, url); } else { - let stack = stacks.get(host); - saveLayout(stack[0]); + saveLayout(); globalThis.history.scrollRestoration = "manual"; globalThis.history.pushState([entry, ...state], "", url);