Overflow list
A row of items that shows as many as fit and puts the rest in a '+N' menu.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- 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
Props
OverflowListProps
| Prop | Type | Default | Description |
|---|---|---|---|
items required | OverflowItem[] | – | 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.
| Attribute | Stylesheet |
|---|---|
[data-hidden] | overflow-list.css |
CSS classes
| Class | Stylesheet |
|---|---|
.btn | 02-buttons.css |
.btn-block | 02-buttons.css |
.btn-danger | 02-buttons.css |
.btn-ghost | 02-buttons.css |
.btn-lg | 02-buttons.css |
.btn-line | 02-buttons.css |
.btn-sm | 02-buttons.css |
.btn-solid | 02-buttons.css |
.danger | 17-dropdown-menu.css |
.dropdown | 17-dropdown-menu.css |
.menu | 17-dropdown-menu.css |
.menu-end | 17-dropdown-menu.css |
.menu-item | 17-dropdown-menu.css |
.menu-sep | 17-dropdown-menu.css |
.overflow-list | overflow-list.css |
.overflow-list-item | overflow-list.css |
.overflow-list-items | overflow-list.css |
.overflow-list-more | overflow-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
| Keys | Action |
|---|---|
| Space / ArrowDown | Opens, arrows move |
| Escape | Closes and returns focus to the button |