Playground

Overflow list

A row of items that shows as many as fit and puts the rest in a '+N' menu.

  • Built on native elements
  • Items that do not fit are visibility:hidden, so they are neither focusable nor read out; the same items are reachable in the menu.
  • The '+N' button is named '3 more items' (customisable with moreLabel) and opens a menu: Enter, Space or ArrowDown opens, arrows move, Escape closes and returns focus to the button.
  • Layout is recalculated by a ResizeObserver when the container or the items change.
  • Styles in one file: 02-buttons.css

Import

import '@monoline/css';
import {OverflowList} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add overflow-list

Usage

import {OverflowList, Tag} from '@monoline/react';

const names = ['Design', 'Engineering', 'Marketing', 'Support', 'Finance', 'Legal', 'People', 'Research'];

<div style={{maxWidth: '320px', resize: 'horizontal', overflow: 'auto', paddingBlock: 'var(--s2)'}}>
  <OverflowList items={names.map((n) => ({id: n, label: <Tag>{n}</Tag>}))} />
</div>

Examples

Tags in a narrow box

Resize the window: items move in and out of the menu.

Props

OverflowListProps

PropTypeDefaultDescription
items requiredOverflowItem[]–The items in order. As many as fit are shown; the rest move into a "+N" menu.
moreLabel((hidden: number) => string)(n) => `${n} more ${n === 1 ? 'item' : 'items'}`Accessible name of the "+N" button, given the number of hidden items. Default "N more items".

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[data-hidden]overflow-list.css

CSS classes

ClassStylesheet
.btn02-buttons.css
.btn-block02-buttons.css
.btn-danger02-buttons.css
.btn-ghost02-buttons.css
.btn-lg02-buttons.css
.btn-line02-buttons.css
.btn-sm02-buttons.css
.btn-solid02-buttons.css
.danger17-dropdown-menu.css
.dropdown17-dropdown-menu.css
.menu17-dropdown-menu.css
.menu-end17-dropdown-menu.css
.menu-item17-dropdown-menu.css
.menu-sep17-dropdown-menu.css
.overflow-listoverflow-list.css
.overflow-list-itemoverflow-list.css
.overflow-list-itemsoverflow-list.css
.overflow-list-moreoverflow-list.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.btn {
  border-color: var(--accent);
}
.btn[data-hidden] {
  background: var(--wash);
}

Accessibility

  • Items that do not fit are visibility:hidden, so they are neither focusable nor read out; the same items are reachable in the menu.
  • The '+N' button is named '3 more items' (customisable with moreLabel) and opens a menu: Enter, Space or ArrowDown opens, arrows move, Escape closes and returns focus to the button.
  • Layout is recalculated by a ResizeObserver when the container or the items change.

Keyboard

KeysAction
Space / ArrowDownOpens, arrows move
EscapeCloses and returns focus to the button