Overflow Items
Measures how many items fit in a container and tracks the overflow count. Uses ResizeObserver for automatic recalculation. Single ref — no hidden measurement rows needed.
Installation
dgadd ships in @diffgazer/add on npm: pnpm add -D @diffgazer/add puts it on pnpm exec, and npx @diffgazer/add runs it without the install.
UI components require Tailwind CSS v4. Local copy mode imports src/styles/styles.css; package mode uses @diffgazer/ui CSS from the installed package.
Parameters
Returns
Examples
Basic Overflow Badge
Notes
Container Contract
The container's children must follow this order: [item0, item1, ..., itemN-1, indicator]. The first itemCount children are measured as items. The child at index itemCount is measured as the overflow indicator. The container must use CSS gap (e.g. Tailwind gap-* or gap-x-*) — the hook reads the resolved column-gap via getComputedStyle, since it measures a single horizontal row.
Hiding Overflow Items
Items where index >= visibleCount should get 'invisible absolute pointer-events-none' classes. This keeps them in the DOM for measurement while hiding them visually. The indicator should always be rendered (hidden when overflowCount === 0) so the hook can measure its width for space reservation.
No Visual Flash
The hook uses useLayoutEffect which fires before the browser paints. On the first render all items are visible in the flex flow, measured synchronously, then visibleCount is set — triggering a re-render before paint. The user never sees the intermediate state.
Source
Highlighted source loads after this disclosure opens. Browse the source repository.