This commit is contained in:
2025-11-12 17:02:27 +01:00
parent d2e27c12a2
commit b812d748ea
44 changed files with 221 additions and 356 deletions
+5 -23
View File
@@ -5,19 +5,12 @@ import { clamp } from '../utils/math';
const noop = () => {};
const ensureDocumentRoot = () => {
if (typeof document === 'undefined') {
return null;
}
return document.body;
};
const PreviewZoomOverlay = ({
open = false,
display = null,
onClose = noop,
}) => {
const portalTarget = ensureDocumentRoot();
const portalTarget = document.body;
const [isNativeScale, setIsNativeScale] = useState(false);
const [naturalSize, setNaturalSize] = useState({ width: null, height: null });
const [renderBackdrop, setRenderBackdrop] = useState(false);
@@ -125,21 +118,13 @@ const PreviewZoomOverlay = ({
useEffect(() => {
if (!open) {
if (previouslyFocusedRef.current && typeof previouslyFocusedRef.current.focus === 'function') {
previouslyFocusedRef.current.focus();
}
previouslyFocusedRef.current?.focus?.();
previouslyFocusedRef.current = null;
return;
}
if (typeof document !== 'undefined') {
const active = document.activeElement;
if (active && typeof active.focus === 'function') {
previouslyFocusedRef.current = active;
} else {
previouslyFocusedRef.current = null;
}
}
const active = document.activeElement;
previouslyFocusedRef.current = active?.focus ? active : null;
}, [open]);
const activeDisplay = open && display?.url ? display : displaySnapshot;
@@ -163,10 +148,7 @@ const PreviewZoomOverlay = ({
}
const frame = requestAnimationFrame(() => {
const scrollEl = scrollRef.current;
if (scrollEl && typeof scrollEl.focus === 'function') {
scrollEl.focus({ preventScroll: true });
}
scrollRef.current?.focus?.({ preventScroll: true });
});
return () => cancelAnimationFrame(frame);