Todae

Todae

ChipList

A list of chips that shows up to maxRows rows and folds the rest into a +N button. +N opens a popover with the folded chips. Name the list with aria-label or aria-labelledby.

On this page

With onRemove, each chip gets a remove button. Once chips drops the focused chip, focus moves to the chip that now fills its place, else the one before it, else +N, else the list.

<ChipList.Root
  aria-label="Tags"
  chips={tags}
  maxRows={1}
  onRemove={(index) => setTags((current) => current.filter((_, i) => i !== index))}
/>

In the popover, Tab past the last chip goes on to the control after +N, Shift+Tab from the first chip returns to +N, and Escape closes it and returns to +N.

getTone gives each chip a tone, as on Chip. To color tags by name, pass categoryTone, which maps a string to the same category tone every time: getTone={(value) => categoryTone(value)}.

One row / Two rows

import { ChipList } from '@tounsoo/todae';
import { useState } from 'react';

const TAGS = ['design', 'tokens', 'accessibility', 'a-very-long-tag-that-stays-put', 'react', 'density', 'dark mode', 'docs'];

export default function ChipListOneRow() {
  const [chips, setChips] = useState(TAGS);
  return (
    <div style={{ width: '100%', maxWidth: '18rem', minWidth: 0 }}>
      <ChipList.Root
        aria-label="Tags"
        chips={chips}
        maxRows={1}
        overflowLabel={(n) => `+${n} more`}
        panelLabel={(n) => `${n} more ${n === 1 ? 'tag' : 'tags'}`}
        onRemove={(index) => setChips((current) => current.filter((_, i) => i !== index))}
      />
    </div>
  );
}
designtokensaccessibilitya-very-long-tag-that-stays-putreactdensitydark modedocs
import { ChipList } from '@tounsoo/todae';
import { useState } from 'react';

const TAGS = ['design', 'tokens', 'accessibility', 'a-very-long-tag-that-stays-put', 'react', 'density', 'dark mode', 'docs'];

export default function ChipListTwoRows() {
  const [chips, setChips] = useState(TAGS);
  return (
    <div style={{ width: '100%', maxWidth: '18rem', minWidth: 0 }}>
      <ChipList.Root
        aria-label="Tags"
        chips={chips}
        maxRows={2}
        overflowLabel={(n) => `+${n} more`}
        panelLabel={(n) => `${n} more ${n === 1 ? 'tag' : 'tags'}`}
        onRemove={(index) => setChips((current) => current.filter((_, i) => i !== index))}
      />
    </div>
  );
}
designtokensaccessibilitya-very-long-tag-that-stays-putreactdensitydark modedocs

Read-only

Leave out onRemove, and the chips have no remove buttons.

<ChipList.Root aria-label="Tags" chips={tags} maxRows={1} />
import { ChipList } from '@tounsoo/todae';

const TAGS = ['design', 'tokens', 'accessibility', 'a-very-long-tag-that-stays-put', 'react', 'density', 'dark mode', 'docs'];

export default function ChipListReadOnly() {
  return (
    <div style={{ width: '100%', maxWidth: '18rem', minWidth: 0 }}>
      <ChipList.Root
        aria-label="Tags"
        chips={TAGS}
        maxRows={1}
        overflowLabel={(n) => `+${n} more`}
        panelLabel={(n) => `${n} more ${n === 1 ? 'tag' : 'tags'}`}
      />
    </div>
  );
}
designtokensaccessibilitya-very-long-tag-that-stays-putreactdensitydark modedocs

Icons

Remove buttons show the close glyph, a cross unless a GlyphsProvider sets one. Pass removeIcon to use a different icon for this list, as on Chip.

Accessible composition

Todae handles: The chips sit in a role="list" element that gets your aria-label, aria-labelledby, aria-describedby and aria-details. Each chip in the row, and +N, is a role="listitem". +N is a native button with aria-expanded, aria-controls and aria-haspopup="dialog", named by overflowLabel or the moreChips string. The popover is a role="dialog" named by panelLabel or the moreChipsPanel string. Remove buttons are named by removeLabel or Remove {value}. Focus after a removal, and Tab, Shift+Tab and Escape in the popover, work as described above. The measure row is aria-hidden and inert.

You supply: aria-label or aria-labelledby that says what the chips are, such as "Applied filters". Without one the list has no name. A removeLabel when Remove {value} is not enough on its own. A stable getKey when two chips can share a value, so focus follows the right one. Any announcement of a change made elsewhere, such as filters cleared by another button: the list announces nothing.

Watch for: Naming a wrapper instead of the list: aria-label on ChipList.Root reaches the list, but on your own <div> around it, it names nothing. Removing by value when values repeat: onRemove passes the index of the chip that was pressed. A wrapper that always passes onRemove, which gives read-only chips a remove button.

When to use

When: Chips outside a text field, such as applied filters (see the Filter bar recipe), read-only tags or recipients, capped at maxRows with a +N count.

When not: Typing new chips → Field.ChipInput. Picking from options → Combobox recipe. Selectable or toggle chips → Checkbox / Button.Root. One chip → Chip.Root. Your own markup around the fold → useChipList.

Props

ChipList.Root props
NameTypeDescription
chips Requiredreadonly string[]

Chip labels, in order.

maxRowsnumber

Rows to show before folding the rest into +N. Without it, every chip wraps onto as many rows as it needs.

getKey(value: string, index: number) => string

A stable, unique key for each chip, so focus can follow it when chips change. Without it, chips are matched by value, so focus can land on another chip with the same value.

getTone(value: string, index: number) => ChipTone

Each chip's tone, such as (value) => categoryTone(value). Without it, every chip is neutral.

onRemove(index: number, value: string) => void

Renders a remove button on each chip. Once chips drops the focused chip, focus moves to the chip that now fills its place, else the one before it, else +N, else the list.

removeLabel(value: string) => string

Remove button name. Default is the removeChip string from StringsProvider, Remove {value} in English.

removeIconReact.ReactNode

Remove button content, such as an icon from your own set. Without it, the close glyph from GlyphsProvider, else Todae's cross.

overflowLabel(n: number) => string

+N button name. Default is the moreChips string from StringsProvider, {n} more in English.

panelLabel(n: number) => string

Name of the popover with the folded chips. Default is the moreChipsPanel string from StringsProvider, {n} more chips or 1 more chip in English.