@blockle/blocks 0.8.3 → 0.8.4
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/dist/index.cjs +10 -8
- package/dist/index.mjs +10 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -415,16 +415,18 @@ const usePreventBodyScroll = (enabled = true) => {
|
|
|
415
415
|
};
|
|
416
416
|
}, [enabled]);
|
|
417
417
|
};
|
|
418
|
+
const isBrowser = typeof window !== "undefined";
|
|
418
419
|
const useRestoreFocus = (active) => {
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
}, [active]);
|
|
420
|
+
const target = react.useRef(null);
|
|
421
|
+
if (isBrowser && active && !target.current) {
|
|
422
|
+
target.current = document.activeElement;
|
|
423
|
+
}
|
|
425
424
|
react.useEffect(() => {
|
|
426
|
-
if (!active && target instanceof HTMLElement) {
|
|
427
|
-
target.focus();
|
|
425
|
+
if (target.current && !active && target.current instanceof HTMLElement) {
|
|
426
|
+
target.current.focus();
|
|
427
|
+
}
|
|
428
|
+
if (!active) {
|
|
429
|
+
target.current = null;
|
|
428
430
|
}
|
|
429
431
|
}, [active]);
|
|
430
432
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -415,16 +415,18 @@ const usePreventBodyScroll = (enabled = true) => {
|
|
|
415
415
|
};
|
|
416
416
|
}, [enabled]);
|
|
417
417
|
};
|
|
418
|
+
const isBrowser = typeof window !== "undefined";
|
|
418
419
|
const useRestoreFocus = (active) => {
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
}, [active]);
|
|
420
|
+
const target = useRef(null);
|
|
421
|
+
if (isBrowser && active && !target.current) {
|
|
422
|
+
target.current = document.activeElement;
|
|
423
|
+
}
|
|
425
424
|
useEffect(() => {
|
|
426
|
-
if (!active && target instanceof HTMLElement) {
|
|
427
|
-
target.focus();
|
|
425
|
+
if (target.current && !active && target.current instanceof HTMLElement) {
|
|
426
|
+
target.current.focus();
|
|
427
|
+
}
|
|
428
|
+
if (!active) {
|
|
429
|
+
target.current = null;
|
|
428
430
|
}
|
|
429
431
|
}, [active]);
|
|
430
432
|
};
|