1
0
Fork 0

fix(grids): resize drag preview when rotating mid-drag

dnd-kit pins the DragOverlay container to the activator rect measured
at drag start, so pressing R while dragging left the preview at the
pre-rotation footprint (a square-ish box for elongated items). Pass the
live rotated dimensions through the DragOverlay style prop, which is
spread after the pinned rect, in all three R-to-rotate grids: garage
vehicle bay, locker, and structure storage.
This commit is contained in:
Jason Fraley 2026-10-13 16:42:50 -04:00
parent 0453742f32
commit 7c135cd282
3 changed files with 49 additions and 5 deletions

View file

@ -346,6 +346,16 @@ export function GarageGrid({
}
};
// Drag preview must track mid-drag rotation: dnd-kit pins the overlay
// container to the activator rect captured at drag start, so we override
// its width/height via the style prop (spread after the pinned rect).
const overlayFp = activeItem
? {
width: pendingRotated ? activeItem.height : activeItem.width,
height: pendingRotated ? activeItem.width : activeItem.height,
}
: null;
return (
<DndContext
sensors={sensors}
@ -406,9 +416,16 @@ export function GarageGrid({
{canEdit && <span className="ml-auto normal-case">drag to move &middot; R to rotate</span>}
</div>
</div>
<DragOverlay dropAnimation={null}>
<DragOverlay
dropAnimation={null}
style={
overlayFp
? { width: overlayFp.width * cellSize, height: overlayFp.height * cellSize }
: undefined
}
>
{activeItem ? (
<div className="rounded-md border border-primary/50 bg-card/95 shadow-xl">
<div className="h-full w-full rounded-md border border-primary/50 bg-card/95 shadow-xl">
<VehicleFace item={{ ...activeItem, rotated: pendingRotated }} cellSize={cellSize} dragging />
</div>
) : null}

View file

@ -544,6 +544,13 @@ export function LockerGrid({
onSelectItem(null);
}, [onSelectItem]);
// Drag preview must track mid-drag rotation: dnd-kit pins the overlay
// container to the activator rect captured at drag start, so we override
// its width/height via the style prop (spread after the pinned rect).
const overlayFp = activeItem
? getLockerItemFootprint(activeItem.asset, pendingRotated)
: null;
return (
<DndContext
sensors={sensors}
@ -635,9 +642,16 @@ export function LockerGrid({
</div>
{/* Tactical drag overlay */}
<DragOverlay dropAnimation={null}>
<DragOverlay
dropAnimation={null}
style={
overlayFp
? { width: overlayFp.width * cellSize, height: overlayFp.height * cellSize }
: undefined
}
>
{activeItem && (
<div className="rounded-sm border border-primary/50 bg-card shadow-lg ring-2 ring-primary/40">
<div className="h-full w-full rounded-sm border border-primary/50 bg-card shadow-lg ring-2 ring-primary/40">
<LockerItemFace
asset={activeItem.asset}
quantity={activeItem.quantity}

View file

@ -353,7 +353,20 @@ export function InventoryGrid({
</div>
</div>
<DragOverlay dropAnimation={null}>
<DragOverlay
dropAnimation={null}
style={
activeItem
? (() => {
// dnd-kit pins the overlay container to the activator rect
// from drag start; override width/height so mid-drag rotation
// resizes the preview (style is spread after the pinned rect).
const fp = getItemFootprint(activeItem.resource as Resource, pendingRotated);
return { width: fp.width * cellSize - 2, height: fp.height * cellSize - 2 };
})()
: undefined
}
>
{activeItem && (
<DragOverlayContent item={activeItem} cellSize={cellSize} rotated={pendingRotated} />
)}