@sveltejs/kit 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/runtime/client/client.js +20 -8
package/package.json
CHANGED
|
@@ -326,13 +326,22 @@ export function create_client({ target, base }) {
|
|
|
326
326
|
// opts must be passed if we're navigating
|
|
327
327
|
if (opts) {
|
|
328
328
|
const { scroll, keepfocus } = opts;
|
|
329
|
+
const { activeElement } = document;
|
|
329
330
|
|
|
330
|
-
//
|
|
331
|
-
if (!keepfocus) reset_focus();
|
|
332
|
-
|
|
333
|
-
// need to render the DOM before we can scroll to the rendered elements
|
|
331
|
+
// need to render the DOM before we can scroll to the rendered elements and do focus management
|
|
334
332
|
await tick();
|
|
335
333
|
|
|
334
|
+
const changed_focus =
|
|
335
|
+
// reset focus only if any manual focus management didn't override it
|
|
336
|
+
document.activeElement !== activeElement &&
|
|
337
|
+
// also refocus when activeElement is body already because the
|
|
338
|
+
// focus event might not have been fired on it yet
|
|
339
|
+
document.activeElement !== document.body;
|
|
340
|
+
|
|
341
|
+
if (!keepfocus && !changed_focus) {
|
|
342
|
+
await reset_focus();
|
|
343
|
+
}
|
|
344
|
+
|
|
336
345
|
if (autoscroll) {
|
|
337
346
|
const deep_linked = url.hash && document.getElementById(url.hash.slice(1));
|
|
338
347
|
if (scroll) {
|
|
@@ -1718,16 +1727,19 @@ function reset_focus() {
|
|
|
1718
1727
|
root.tabIndex = -1;
|
|
1719
1728
|
root.focus({ preventScroll: true });
|
|
1720
1729
|
|
|
1721
|
-
setTimeout(() => {
|
|
1722
|
-
getSelection()?.removeAllRanges();
|
|
1723
|
-
});
|
|
1724
|
-
|
|
1725
1730
|
// restore `tabindex` as to prevent `root` from stealing input from elements
|
|
1726
1731
|
if (tabindex !== null) {
|
|
1727
1732
|
root.setAttribute('tabindex', tabindex);
|
|
1728
1733
|
} else {
|
|
1729
1734
|
root.removeAttribute('tabindex');
|
|
1730
1735
|
}
|
|
1736
|
+
|
|
1737
|
+
return new Promise((resolve) => {
|
|
1738
|
+
setTimeout(() => {
|
|
1739
|
+
// fixes https://github.com/sveltejs/kit/issues/8439
|
|
1740
|
+
resolve(getSelection()?.removeAllRanges());
|
|
1741
|
+
});
|
|
1742
|
+
});
|
|
1731
1743
|
}
|
|
1732
1744
|
}
|
|
1733
1745
|
|