|Kit

PillsInput

A multi-line input shell that lays out removable pills alongside a search field — the target MultiSelect and TagsInput mount into.

PillsInput is the input shell for multi-value fields. It wears the same chrome as Input — border, focus ring, invalid / disabled states — but wraps as values pile up, laying out Pills next to a search field. It's the target MultiSelect and TagsInput render into; reach for it directly when you're wiring your own multi-value control.

import { PillsInput } from '@42-central/ui-react/pills-input';
import { Pill } from '@42-central/ui-react/pill';

<PillsInput>
  {values.map((v) => (
    <Pill key={v} withRemoveButton onRemove={() => remove(v)}>{v}</Pill>
  ))}
  <PillsInput.Field placeholder="Add a skill…" />
</PillsInput>

Presentational by design — it holds no value state. Drive the values yourself, or let MultiSelect / TagsInput do it.

Playground

PillsInput

Loading preview

Props

Code

<PillsInput size="md" placeholder="Add a tag…" />

Anatomy

Host Pills and a single PillsInput.Field inside. The shell sets the pill size and disabled through context, so the pills match the field with no extra props. PillsInput.Field grows to fill the current line and pops the last value on Backspace-when-empty.

'use client';
import { useState } from 'react';
import { PillsInput } from '@42-central/ui-react/pills-input';
import { Pill } from '@42-central/ui-react/pill';

export function TagField() {
  const [values, setValues] = useState<string[]>(['c', 'unix']);
  const [search, setSearch] = useState('');

  const add = (raw: string) => {
    const v = raw.trim();
    if (v && !values.includes(v)) setValues((cur) => [...cur, v]);
    setSearch('');
  };

  return (
    <PillsInput>
      {values.map((v) => (
        <Pill key={v} withRemoveButton onRemove={() => setValues((cur) => cur.filter((x) => x !== v))}>
          {v}
        </Pill>
      ))}
      <PillsInput.Field
        value={search}
        placeholder={values.length === 0 ? 'Add a skill…' : ''}
        onChange={(e) => setSearch(e.currentTarget.value)}
        onKeyDown={(e) => {
          if (e.key === 'Enter') { e.preventDefault(); add(search); }
        }}
        onRemoveLast={() => setValues((cur) => cur.slice(0, -1))}
      />
    </PillsInput>
  );
}

Sizes & variants

size (xs–xl) and variant (default / unstyled) match Input — try them in the Playground above. The shell grows in height as pills wrap, and the pills scale to the chosen size automatically.

Max lines

maxLines caps the pills at N rows; any beyond collapse into a static +N counter (measured, so it adapts to the field width). The convention is pills first, the field last — only the pills are capped; the field always stays visible. Since PillsInput has no dropdown, the hidden pills aren't individually removable while capped, so it's best when you also surface the full set elsewhere. The counter is drawn in the locale's digits (+٣ under ar-EG) and is hidden from screen readers, which hear translations.overflowCount instead ("3 more items" by default) rather than "plus 3".

designuiuxreactvuesvelteangularsolidqwikember

Start & end slots

startSlot and endSlot flank the pills region with the same slot layout as Input — drop in a leading icon or a trailing control. They sit outside the wrapping pills, so a trailing control stays pinned as the pills wrap.

In Field

Like the rest of the family, wrap it in Field for a label, description, and error:

<Field label="Tags" description="Press Enter to add">
  <TagField />
</Field>

usePillOverflow

The line cap is a hook, so a row of pills of your own can have it too: a read-only list of tags in a table cell, a trigger with no field. PillsInput and TreeMultiSelect's trigger are built on it. It's exported from the same entry, with the counter, PillOverflowCounter:

import { PillOverflowCounter, usePillOverflow } from '@42-central/ui-react/pills-input';

const { containerRef, visibleCount, hiddenCount, measuring } = usePillOverflow({
  maxLines: 1,
  count: tags.length,
});

<div ref={containerRef} className="flex flex-wrap gap-1.5">
  {tags.slice(0, visibleCount).map((tag) => (
    <Pill key={tag} data-overflow-item>{tag}</Pill>
  ))}
  {(hiddenCount > 0 || measuring) && (
    <PillOverflowCounter
      count={measuring ? tags.length : hiddenCount}
      className={measuring ? 'invisible' : undefined}
    />
  )}
</div>

Line breaks depend on each pill's width, so the hook measures the DOM. It renders every pill in a measuring pass before paint, groups them into rows by their offset, and settles on how many fit, keeping room on the last row for the +N counter. It measures again when the container's width changes (not its height, which its own slicing changes) and when count or maxLines does.

The markup tells it what's what:

  • Each pill carries data-overflow-item. Only these are counted.
  • The counter carries data-overflow-counter, which PillOverflowCounter sets for you. Keep it mounted, invisible, while measuring, so its real width is reserved.
  • A trailing field, if there is one, carries data-overflow-field (PillsInput.Field does). The hook then keeps the field's min-width free on the last row, so the field never wraps onto a line of its own.
TypeScriptReactAccessibilityCSS GridTestingGraphQLDesign systemsNode.jsRustPostgreSQL

Drag the box's corner: 10 shown, 0 hidden.

Code

const { containerRef, visibleCount, hiddenCount, measuring } = usePillOverflow({
  maxLines: 1,
  count: skills.length,
});

On the server, and with no maxLines, every pill renders: visibleCount is count, the right fallback before anything can be measured.

Prop

Type

Prop

Type

PillOverflowCounter takes count, size, className and translations (only overflowCount is read). It draws the +N in the locale's digits, hidden from screen readers, which hear overflowCount instead.

API

PillsInput

Prop

Type

PillsInput.Field

Prop

Type

PillsInput.Field forwards every other prop to the underlying <input> (value, onChange, placeholder, onKeyDown, …). PillsInput forwards to its root div.

PillsInput and PillsInput.Field each take their own testId prop landing on different elements: the base PillsInput's testId lands on its own shell <div> — useful mainly when it's used bare — while PillsInput.Field's testId lands on the real <input>. See the Testing guide.

Accessibility

  • PillsInput.Field is a real <input> — label it via Field (or aria-label).
  • Backspace on the empty field removes the last value (onRemoveLast), matching the expected tag-field interaction; each pill's × is independently focusable and labelled.
  • RTL: the pills region is a wrapping flex row with logical start/end slots, so pills, field, and any adornments flow correctly under dir="rtl".

Changelog

v0.30.0
  • Controls with no label or Field now dim in a disabled Fieldset and turn red in an invalid one

    #493
v0.20.0
  • The "+N" counter uses the locale's digits and reads a pluralised "3 more items" through translations.overflowCount; PillsInput gains translations

    #387
  • Pill labels no longer clip descenders and accents ("qwik" read as "awik")

    #408
v0.18.0
  • asChild is a compile error on CircularProgress, Progress, Rating, Slider, Divider, Field, InputBase and PillsInput

    #294
v0.0.1
  • Input, Field, PillsInput and Pill: the shared input shell, label/help/error wrapper and chips

On this page