fix: render inventory actions menu in a portal so it is not clipped
The «عملیات» dropdown was absolutely positioned inside the table container, which has overflow:hidden for its rounded corners, so the menu was clipped below the table. Render it through a Portal with fixed positioning computed from the trigger's rect (RTL-aligned to the trigger's right edge), tracking scroll/resize while open. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useLayoutEffect, useRef, useState } from 'react';
|
||||||
import { EllipsisHorizontalCircleIcon, PencilSquareIcon, TrashIcon } from '@heroicons/react/24/outline';
|
import { EllipsisHorizontalCircleIcon, PencilSquareIcon, TrashIcon } from '@heroicons/react/24/outline';
|
||||||
|
import Portal from '../ui/Portal';
|
||||||
import type { InventoryItem } from '../../hooks/useInventory';
|
import type { InventoryItem } from '../../hooks/useInventory';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -8,13 +9,39 @@ interface Props {
|
|||||||
onDelete: (item: InventoryItem) => void;
|
onDelete: (item: InventoryItem) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** «عملیات» trigger + dropdown — mirrors the tauri InventoryActionsPopover. */
|
const MENU_W = 160;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* «عملیات» trigger + dropdown — mirrors the tauri InventoryActionsPopover.
|
||||||
|
* Rendered through a Portal with fixed positioning so it is never clipped by the
|
||||||
|
* table container's `overflow: hidden`.
|
||||||
|
*/
|
||||||
export default function InventoryActionsMenu({ item, onEdit, onDelete }: Props) {
|
export default function InventoryActionsMenu({ item, onEdit, onDelete }: Props) {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
const [pos, setPos] = useState<{ top: number; left: number }>({ top: 0, left: 0 });
|
||||||
|
const triggerRef = useRef<HTMLButtonElement>(null);
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
if (!open || !triggerRef.current) return;
|
||||||
|
const place = () => {
|
||||||
|
const r = triggerRef.current!.getBoundingClientRect();
|
||||||
|
// align the menu's right edge to the trigger's right edge (RTL-friendly)
|
||||||
|
const left = Math.max(8, Math.min(r.right - MENU_W, window.innerWidth - MENU_W - 8));
|
||||||
|
setPos({ top: r.bottom + 4, left });
|
||||||
|
};
|
||||||
|
place();
|
||||||
|
window.addEventListener('scroll', place, true);
|
||||||
|
window.addEventListener('resize', place);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('scroll', place, true);
|
||||||
|
window.removeEventListener('resize', place);
|
||||||
|
};
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ position: 'relative', display: 'inline-block' }}>
|
<>
|
||||||
<button
|
<button
|
||||||
|
ref={triggerRef}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setOpen((v) => !v)}
|
onClick={() => setOpen((v) => !v)}
|
||||||
style={{
|
style={{
|
||||||
@@ -28,16 +55,13 @@ export default function InventoryActionsMenu({ item, onEdit, onDelete }: Props)
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
{open && (
|
{open && (
|
||||||
<>
|
<Portal>
|
||||||
<div
|
<div onClick={() => setOpen(false)} style={{ position: 'fixed', inset: 0, zIndex: 60 }} />
|
||||||
onClick={() => setOpen(false)}
|
|
||||||
style={{ position: 'fixed', inset: 0, zIndex: 30 }}
|
|
||||||
/>
|
|
||||||
<div
|
<div
|
||||||
role="menu"
|
role="menu"
|
||||||
style={{
|
style={{
|
||||||
position: 'absolute', top: '100%', insetInlineStart: 0, marginTop: 4, zIndex: 31,
|
position: 'fixed', top: pos.top, left: pos.left, zIndex: 61,
|
||||||
width: 160, background: 'var(--surface)', border: '1px solid var(--border)',
|
width: MENU_W, background: 'var(--surface)', border: '1px solid var(--border)',
|
||||||
borderRadius: 12, boxShadow: 'var(--shadow-lg)', overflow: 'hidden',
|
borderRadius: 12, boxShadow: 'var(--shadow-lg)', overflow: 'hidden',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -68,8 +92,8 @@ export default function InventoryActionsMenu({ item, onEdit, onDelete }: Props)
|
|||||||
حذف
|
حذف
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</Portal>
|
||||||
)}
|
)}
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user