Overflow Row
Items on one line, as many as fit, the rest counted in a chip that names them.
Installation
pnpm dlx @human-kit/design add overflow-rownpx @human-kit/design add overflow-rowyarn dlx @human-kit/design add overflow-rowbunx @human-kit/design add overflow-rowThe command copies the files to src/lib/components/ui/overflow-row. It also
installs the packages that the files import.
Usage
<script lang="ts">
import * as Badge from '$lib/components/ui/badge';
import * as OverflowRow from '$lib/components/ui/overflow-row';
</script>
<OverflowRow.Root items={tags} getKey={(tag) => tag} getLabel={(tag) => tag}>
{#snippet children({ item })}
<Badge.Root variant="outline" dot={false}>{item}</Badge.Root>
{/snippet}
</OverflowRow.Root> Examples
In a table cell
The row measures the cell it sits in, padding taken off, so a column of treatments keeps every patient to one line. Give the column a width, here one its grip can change: drag it and the badges fold into the chip, or come back out.
| Patient | Treatments | Cycle day |
|---|---|---|
| Ana Gómez | IVF ICSI PGT-A Frozen transfer | 12 |
| Lucía Pérez | Egg freezing | 3 |
| Marta Díaz | Donor eggs IVF Frozen transfer Luteal support Second cycle | 21 |
| Sofía Romero | IUI Ovulation induction | 8 |
Beside a name
In a line shared with something that keeps its width, wrap the row in a min-w-0 flex-1 box: that box is what the row measures. Badges with a tone fold the same way. The chip stays a plain count, and moreLabel says what it counts, "2 more flags".
- Ana Gómez Latex allergy Consent pending Interpreter Day 12
- Lucía Pérez Day 3
- Marta Fernández Díaz High risk Donor match Lab results due
In a panel that resizes
The row watches its parent, so it follows a width that changes after it is drawn: a split panel, a sidebar that folds, a window made narrower. Drag the divider.
A count alone
Without getLabel the chip is plain text, "+3", and no stop for the keyboard. Use it where the hidden items are one press away anyway, as in a row that opens a detail.
Sharing the line
The row measures its parent. When something else sits beside it in that parent, as a button, give its width in reserve and the row leaves that much free.
Guidelines
- Use it for a list of short labels that must keep to one line: the tags of a record, the people on a case, the filters in force.
- Give
getLabelwhenever the items have a name: the chip becomes a button whose tooltip lists what it hides. - Keep the items about the same size. The row shows them in order, so one long item early on pushes the short ones after it out.
- Put it in a box of a known width, a table cell or a card. In a box that grows with its content everything fits, and nothing is counted.
- For a list the reader has to scan in full, let it wrap on several lines instead.
Accessibility
- The hidden items are not rendered: a screen reader reads the ones shown, then the count.
- The chip reads "3 more", from
moreLabel. The "+3" that the eye sees is hidden from screen readers. - With
getLabelthe chip is a<button>named "3 more: PGT-A, ICSI, Second cycle", so the names are reachable by the keyboard and by touch, not only on hover. - The row clips sideways, and it pads its ends by 4px so the focus ring of a chip or an item is not cut.
API reference
| Prop | Type | Default |
|---|---|---|
items | T[] The full list, in the order to show it. | — |
getKey | (item: T, index: number) => string | number A stable key for each item, for the keyed loop and the measure. | — |
children | Snippet<[{ item: T; index: number }]> Draws one item. It renders twice, once more out of sight to be measured, so it must not have effects. | — |
getLabel | (item: T) => string The name of an item. With it the chip is a button with a tooltip of the hidden names. | — |
moreLabel | string The word read after the count: "3 more". | 'more' |
reserve | number Pixels of the parent to keep free for what sits beside the row. | 0 |
class | string Classes for the row. | — |
Plus every attribute of a <div>, on the row.