fix safari
This commit is contained in:
@@ -121,15 +121,17 @@ export default function UserMenu() {
|
|||||||
const computePosition = useCallback(() => {
|
const computePosition = useCallback(() => {
|
||||||
if (!triggerRef.current) return;
|
if (!triggerRef.current) return;
|
||||||
const r = triggerRef.current.getBoundingClientRect();
|
const r = triggerRef.current.getBoundingClientRect();
|
||||||
|
// visualViewport est fiable sur Safari mobile (window.innerHeight ne l'est pas)
|
||||||
|
const vh = window.visualViewport ? window.visualViewport.height : window.innerHeight;
|
||||||
|
|
||||||
let mainLeft, mainBottom, mainWidth;
|
let mainLeft, mainBottom, mainWidth;
|
||||||
if (sidebarCollapsed) {
|
if (sidebarCollapsed) {
|
||||||
mainLeft = r.right + 8;
|
mainLeft = r.right + 8;
|
||||||
mainBottom = window.innerHeight - r.bottom;
|
mainBottom = vh - r.bottom;
|
||||||
mainWidth = POPUP_W;
|
mainWidth = POPUP_W;
|
||||||
} else {
|
} else {
|
||||||
mainLeft = r.left;
|
mainLeft = r.left;
|
||||||
mainBottom = window.innerHeight - r.top + 6;
|
mainBottom = vh - r.top + 6;
|
||||||
mainWidth = r.width;
|
mainWidth = r.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,9 +166,21 @@ export default function UserMenu() {
|
|||||||
return () => document.removeEventListener('mousedown', onDown);
|
return () => document.removeEventListener('mousedown', onDown);
|
||||||
}, [open, closeMenu]);
|
}, [open, closeMenu]);
|
||||||
|
|
||||||
/* Recalcul si sidebar change */
|
/* Recalcul si sidebar change ou si visualViewport change (Safari mobile) */
|
||||||
useEffect(() => { if (open) computePosition(); }, [sidebarCollapsed, open, computePosition]);
|
useEffect(() => { if (open) computePosition(); }, [sidebarCollapsed, open, computePosition]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
const vp = window.visualViewport;
|
||||||
|
if (!vp) return;
|
||||||
|
vp.addEventListener('resize', computePosition);
|
||||||
|
vp.addEventListener('scroll', computePosition);
|
||||||
|
return () => {
|
||||||
|
vp.removeEventListener('resize', computePosition);
|
||||||
|
vp.removeEventListener('scroll', computePosition);
|
||||||
|
};
|
||||||
|
}, [open, computePosition]);
|
||||||
|
|
||||||
/* Handlers ouverture */
|
/* Handlers ouverture */
|
||||||
const onWrapEnter = () => { if (sidebarCollapsed) { clearClose(); openMenu(); } };
|
const onWrapEnter = () => { if (sidebarCollapsed) { clearClose(); openMenu(); } };
|
||||||
const onWrapLeave = () => { if (sidebarCollapsed) scheduleClose(); };
|
const onWrapLeave = () => { if (sidebarCollapsed) scheduleClose(); };
|
||||||
|
|||||||
Reference in New Issue
Block a user