Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

react-responsive-overflow-list

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-responsive-overflow-list

A responsive React component that shows as many items as can fit within constraints, hiding overflow items behind a configurable overflow renderer

latest
Source
npmnpm
Version
0.3.2
Version published
Weekly downloads
1.5K
-54.17%
Maintainers
1
Weekly downloads
 
Created
Source

react-responsive-overflow-list

Responsive list for React that shows only items that fit and groups the rest into a customizable overflow element. Recalculates on resize.

npm downloads bundle size license

🔗 Live demo: https://eliav2.github.io/react-responsive-overflow-list/

Open in StackBlitz

Screen Recording 2025-09-27 at 15 49 03

Features

  • Accurate & responsive: measures real layout after paint (ResizeObserver), not guessed widths
  • Two usage modes: children (simple) or items + renderItem (structured)
  • Customizable overflow element; ships with a lightweight default
  • Multi-row support (via maxRows)
  • Handles uneven widths, including a single ultra-wide item
  • TypeScript types; zero runtime deps (React as peer)
  • SSR-friendly: measurement runs on the client
  • No implicit wrappers around your items. (layout behaves as you expect)

Install

npm i react-responsive-overflow-list

shadcn/ui

Install as a styled shadcn component with dropdown menu overflow:

# Radix UI primitives (recommended)
npx shadcn@latest add https://eliav2.github.io/react-responsive-overflow-list/r/styles/radix-vega/overflow-list.json

# Base UI primitives
npx shadcn@latest add https://eliav2.github.io/react-responsive-overflow-list/r/styles/base-vega/overflow-list.json

See shadcn/ui docs for usage.

Usage

In real apps, you’ll typically wrap OverflowList in your own component—design tokens, accessible menus, virtualization, or search. See 'Wrap & extend' below and the demo for a full wrapper example.

Items + renderItem (most common)

Minimal usage with an items array and render function.

import { OverflowList } from "react-responsive-overflow-list";

const items = ["One", "Two", "Three", "Four", "Five"];

export default function Example() {
  return (
    <OverflowList
      items={items}
      renderItem={(item) => <span style={{ padding: 4 }}>{item}</span>}
      style={{ gap: 8 }} // root is display:flex; flex-wrap:wrap
      maxRows={1}
    />
  );
}

Children pattern

Use children instead of items + renderItem.

<OverflowList style={{ gap: 8 }}>
  <button>A</button>
  <button>B</button>
  <button>C</button>
  <button>D</button>
</OverflowList>

Custom overflow element

Provide your own overflow UI (button, menu, details/summary, etc.).

<OverflowList
  items={items}
  renderItem={(item) => <span>{item}</span>}
  renderOverflow={(hidden) => <button>+{hidden.length} more</button>}
/>

Polymorphic root

Render using a different HTML element via as.

<OverflowList as="nav">
  <a href="#home">Home</a>
  <a href="#about">About</a>
  <a href="#contact">Contact</a>
</OverflowList>

Performance control

Trade visual smoothness vs peak performance during rapid resize.

<OverflowList
  items={items}
  renderItem={(item) => <span>{item}</span>}
  flushImmediately={false} // uses rAF; faster under rapid resize, may flicker briefly
/>

See the Flush Immediately example in the live demo.

API (most used)

PropTypeDefaultNotes
itemsT[]Use with renderItem. Omit when using children.
renderItem(item: T, index: number) => ReactNodeHow to render each item.
childrenReactNodeAlternative to items + renderItem.
asReact.ElementType"div"Polymorphic root element.
maxRowsnumber1Visible rows before overflow.
maxVisibleItemsnumber100Hard cap on visible items.
renderOverflow(hidden: T[]) => ReactNodedefault chipCustom overflow UI.
renderOverflowItem(item: T, i: number) => ReactNoderenderItemFor expanded lists/menus.
renderOverflowPropsPartial<OverflowElementProps<T>>Props for default overflow.
flushImmediatelybooleantruetrue (flushSync, no flicker) vs false (rAF, faster under resize).
renderItemVisibility(node: ReactNode, meta: RenderItemVisibilityMeta) => ReactNodeinternalControl visibility of hidden items (defaults to React.Activity if available, otherwise simply return null).

Styles: Root uses display:flex; flex-wrap:wrap; align-items:center;. Override via style/className.

Default overflow element: A tiny chip that renders +{count} more. Replace via renderOverflow.

Wrap & extend

It’s expected you’ll wrap OverflowList for product needs (design system styling, a11y menus, virtualization, search). for example:

  • Radix UI + Virtualization wrapper (search, large datasets, a11y, perf):

How it works

  • Measure all items and compute how many fit within maxRows.
  • Re-test with the overflow indicator; if it would create a new row, hide one more item.
  • Render the stable “normal” state until container size changes.

flushImmediately=true → immediate, flicker-free (uses flushSync). flushImmediately=false → defer with rAF; smoother under rapid resize, may flicker.

Edge cases handled

  • Single wide item exceeding container width
  • maxRows / maxVisibleItems respected
  • Varying item widths, responsive content
  • Multi-row overflow detection

Hidden items & React versions

  • In React 19.2+, hidden items use React.Activity so overflowed children stay mounted while toggling visibility.
  • In React 16–18, overflowed nodes unmount during measurement; pass renderItemVisibility if you need to keep custom elements or skeletons mounted and control visibility yourself.

Requirements

  • React ≥ 16.8 (hooks)
  • Modern browsers with ResizeObserver

License

MIT

Keywords

react

FAQs

Package last updated on 21 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts