1
0
Fork 0

fix(garage): always fit the vehicle bay grid to its container

Cell size was computed from the wrapper width without subtracting the
inventory frame's p-2 padding and borders, so the grid was ~16px wider
than its container and grew a horizontal scrollbar. Subtract the 18px
frame chrome, lower the cell floor 40->24 (legibility guard only), and
switch the wrapper to overflow-hidden so no scrollbar can appear.
This commit is contained in:
Jason Fraley 2026-10-13 16:43:16 -04:00
parent 45bb0bd029
commit fe57d63311

View file

@ -264,14 +264,22 @@ export function GarageGrid({
const gridRef = useRef<HTMLDivElement>(null);
const containerRef = useRef<HTMLDivElement>(null);
// Responsive cell size: fit the bay width into the container.
// Chrome between the measured wrapper and the grid: the inventory frame's
// p-2 padding (8+8) plus its 1px borders (1+1).
const FRAME_CHROME_PX = 18;
// Responsive cell size: always fit the bay width into the container (the
// grid must never overflow, so no scrollbar can appear). The small floor is
// a legibility guard only; realistic containers never reach it.
useEffect(() => {
const el = containerRef.current;
if (!el) return;
const observer = new ResizeObserver((entries) => {
const width = entries[0]?.contentRect.width ?? 0;
if (width > 0) {
setCellSize(Math.max(40, Math.min(96, Math.floor(width / gridWidth))));
if (width > FRAME_CHROME_PX) {
setCellSize(
Math.max(24, Math.min(96, Math.floor((width - FRAME_CHROME_PX) / gridWidth))),
);
}
});
observer.observe(el);
@ -388,7 +396,7 @@ export function GarageGrid({
onDragEnd={handleDragEnd}
>
<div className="flex flex-col gap-2">
<div ref={containerRef} className="min-w-0 max-w-full overflow-auto overscroll-contain">
<div ref={containerRef} className="min-w-0 max-w-full overflow-hidden">
<div
className="inventory-frame relative rounded border border-border bg-card/80 p-2 shadow-sm"
role="region"