Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Selected Items List Below Combobox for React

A multi-select topic combobox that starts with Frontend and Backend, a count on the button, and badges below.

The button reads 2 topic(s) selected. Frontend and Backend start selected and show as badges under the field, so the button stays one line as more topics are added.

Use it in a form where the picks should stay visible without crowding the button. Chips inside the field are a Combobox with badges in the control. In React, Base UI keeps the picks as a list.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
Use email insteadNo credit card

Anatomy

Combobox anatomy: control, input, trigger, content, item, item indicator

Usage

<div className="flex flex-col gap-2">
  <Combobox items={topics} multiple onValueChange={setValue} value={value}>
    <ComboboxTrigger
      render={
        <Button className="w-[250px] justify-between" variant="outline" />
      }
    >
      {value.length > 0
        ? `${value.length} topic(s) selected`
        : "Select topics..."}
    </ComboboxTrigger>
    <ComboboxContent>
      <ComboboxInput placeholder="Search topics..." showTrigger={false} />
      <ComboboxEmpty>No topic found.</ComboboxEmpty>
      <ComboboxList>
        {(topic: Topic) => (
          <ComboboxItem key={topic.value} value={topic}>
            {topic.label}
          </ComboboxItem>
        )}
      </ComboboxList>
    </ComboboxContent>
  </Combobox>
  {value.length > 0 ? (
    <div className="flex flex-wrap gap-1">
      {value.map((topic) => (
        <Badge key={topic.value} variant="secondary">
          {topic.label}
        </Badge>
      ))}
    </div>
{/* The rest of the file is under Installation. */}

FAQ

Where is the selection kept?

In the demo's state, passed to Combobox and updated on every change. Both the button and the badges read from it. The value is an array of topic items, starting with the first two.

What does the button show?

The number of picked topics, as 2 topic(s) selected, or Select topics... when none are.

How are the badges rendered?

A flex flex-wrap gap-1 row of secondary Badges, one per picked topic, below the combobox. The row is hidden when nothing is selected.

How do I remove a topic?

Open the list and pick it again: in a multiple combobox a second pick clears it. The badges are display only. Add a remove button to them if people should clear picks from there.

Which topics are listed?

Frontend, Backend, DevOps, Design and Mobile. The search box says Search topics..., and No topic found. shows when nothing matches.

Does the list stay open while picking?

Yes. In multiple mode picking a topic doesn't close the list, so several can be picked in a row.

API Reference

Combobox

Sets items={topics}, multiple, onValueChange={setValue}, value={value}, placeholder="Search topics..." and showTrigger={false}. The rest is on the Combobox page.

Button

Sets variant="outline". The rest is on the Button page.

Badge

Sets variant="secondary". The rest is on the Badge page.