Skip to content

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

Free

With Max Selections Limit Combobox for Ark UI

An interest combobox capped at three picks, which then disables the rest and says the maximum was reached.

The button starts on Select interests... and then counts against the cap, as in 1/3 selected. At three picks, the other rows are disabled and a note says Maximum 3 selections reached.

Use it where a hard limit applies, such as a plan limit or a top-three choice. An unlimited multi-select is a Combobox with no cap. In React, Ark UI does not enforce the limit of 3.

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

<Combobox
  collection={collection}
  multiple
  onInputValueChange={handleInputValueChange}
  onValueChange={handleValueChange}
  positioning={{ getAnchorElement: () => triggerRef.current }}
  value={value}
>
  <ComboboxTrigger
    className={cn(
      buttonVariants({ variant: "outline" }),
      "w-[250px] justify-between"
    )}
    ref={triggerRef}
  >
    {value.length > 0
      ? `${value.length}/${MAX_SELECTIONS} selected`
      : "Select interests..."}
  </ComboboxTrigger>
  <ComboboxContent>
    <ComboboxInput
      className="w-full"
      placeholder="Search interests..."
      showTrigger={false}
    />
    <ComboboxEmpty>No interest found.</ComboboxEmpty>
    {isMaxReached ? (
      <p className="p-2 text-center text-muted-foreground text-xs">
        Maximum {MAX_SELECTIONS} selections reached
      </p>
    ) : null}
{/* The rest of the file is under Installation. */}

FAQ

Where is the limit set?

In a MAX_SELECTIONS constant of 3. The demo compares the number of picks against it on every render.

How are the other rows disabled?

When the cap is reached, every row that isn't picked is disabled. Picked rows stay enabled so they can be unpicked. The collection is rebuilt with createListCollection and an isItemDisabled that checks the cap.

Where does the limit note show?

Above the list, inside ComboboxContent, as a centered muted line. It only renders while the cap is reached.

What does the button show?

The count against the cap, as 1/3 selected, or Select interests... when nothing is picked.

Which interests are listed?

Technology, Science, Art, Music, Sports and Travel. No interest found. shows when the search matches none.

How do I free up a slot?

Pick one of the selected rows again to unpick it. The disabled rows come back as soon as the count drops below three.

API Reference

Combobox

Sets collection={collection}, multiple, onInputValueChange={handleInputValueChange}, onValueChange={handleValueChange}, positioning and getAnchorElement. The rest is on the Combobox page.