npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-responsive-overflow-list

v0.3.3

Published

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

Readme

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)

| Prop | Type | Default | Notes | | ---------------------- | ---------------------------------------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------- | | items | T[] | — | Use with renderItem. Omit when using children. | | renderItem | (item: T, index: number) => ReactNode | — | How to render each item. | | children | ReactNode | — | Alternative to items + renderItem. | | as | React.ElementType | "div" | Polymorphic root element. | | maxRows | number | 1 | Visible rows before overflow. | | maxVisibleItems | number | 100 | Hard cap on visible items. | | renderOverflow | (hidden: T[]) => ReactNode | default chip | Custom overflow UI. | | renderOverflowItem | (item: T, i: number) => ReactNode | renderItem | For expanded lists/menus. | | renderOverflowProps | Partial<OverflowElementProps<T>> | — | Props for default overflow. | | flushImmediately | boolean | true | true (flushSync, no flicker) vs false (rAF, faster under resize). | | renderItemVisibility | (node: ReactNode, meta: RenderItemVisibilityMeta) => ReactNode | internal | Control 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

  1. Measure all items and compute how many fit within maxRows.
  2. Re-test with the overflow indicator; if it would create a new row, hide one more item.
  3. 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