Cascading multi-selector
A combobox for a main choice followed by a multi-select whose options depend on that choice.
Choose a type first. When that type has purposes, the second field appears and receives focus.
When to use
- When the second list depends on the first choice, such as the purposes that exist for each document type.
- In dense rows or inline editing, where both fields sit side by side.
When not to use
- Independent lists. Use two separate fields.
- Choosing several values from one list. Use the multiple selector.
- More than two levels. Use the document tree combobox or a dedicated form.
States
With a selection
Type without secondary options
When the chosen primary value has no secondary options, the second field is not rendered.
Disabled
Content
- Clear the secondary selection when the primary value changes. The component does not do it for you, and old badges may no longer be valid.
- Placeholders say what to pick: “Selecione o tipo”, “Selecione as finalidades”.
- Pass translated placeholders from the app. The defaults are Portuguese.
Accessibility
- It combines a Combobox, built on Radix Popover and
cmdk, and the multiple selector. Their keyboard behavior applies: arrow keys,Enter,Escape, andBackspaceto remove the last badge. - After a primary selection the primary list closes and, when secondary options exist, focus moves to the secondary input. Focus does not move when there are none.
- With
initialFocusTarget="primary"the primary list opens on mount. Use it only for inline editing, where the user just asked to edit. - The secondary field shows one badge and a
+Nbutton when more are selected.
Code
import { CascadingMultiSelector } from "@repo/ui/cascading-multi-selector";
<CascadingMultiSelector
onPrimaryChange={handlePrimaryChange}
onSecondaryChange={setSecondary}
primaryOptions={[{ label: "Contestação", value: "contestacao" }]}
primaryPlaceholder="Selecione o tipo"
primaryValue={primary}
secondaryOptions={purposes}
secondaryPlaceholder="Selecione as finalidades"
selectedSecondary={secondary}
/>;
Props
CascadingMultiSelector| Prop | Type | Default | Description |
|---|---|---|---|
badgeClassName | string | "h-5 text-xs" | Extra classes for the badges of the secondary field |
disabled | boolean | — | Disables both fields |
initialFocusTarget | "primary" | "secondary" | "none" | none | Which field receives focus when the component mounts |
multiTestId | string | "conditional-multi-selector" | Test id of the secondary field |
primaryName | string | "primary-selector" | Name of the primary field |
primaryPlaceholder | string | "Selecione tipo" | Hint of the primary field |
secondaryPlaceholder | string | "Selecione finalidades" | Hint of the secondary field |
More props| Prop | Type | Default | Description |
|---|---|---|---|
primaryOptions | Option[] | — | Options of the primary combobox: { value, label, description? }. |
primaryValue | string | — | Selected primary value. Use an empty string for none. |
onPrimaryChange | (value: string) => void | — | Called when a primary option is chosen. |
secondaryOptions | Option[] | — | Options of the multi-select. When empty, the field is hidden. |
selectedSecondary | Option[] | — | Selected secondary options. |
onSecondaryChange | (items: Option[]) => void | — | Called with the full secondary selection after every change. |
className | string | — | Extra classes for the wrapper, for layout only. |
Known issues
| Issue | Effect |
|---|---|
Neither field receives an accessible name. The component does not pass ariaLabel to the combobox or aria-label to the secondary input. |
Screen readers announce the fields by placeholder or not at all. Apps cannot fix it from props. |
The secondary field always collapses to one badge (collapseSelectedTo={1}) and sets showAllSelectedOnHover, a deprecated prop. |
Users must open +N to see every purpose. It cannot be changed through props. |
The secondary field is forced to !h-10 and the primary trigger to h-10. |
Long selections cannot wrap, so badges are truncated. |
| It inherits the multiple selector issues: opacity-based disabled badges and a clear button with no focus style. | See the multiple selector page. |