@dax-ui/dropdown
v0.8.0
Published
dax-ui Dropdown: select and multi-select with search, groups, icons, descriptions, removable chips and custom colors
Maintainers
Readme
@dax-ui/dropdown
TODO: one or two sentences on what this component is for.
Installation
pnpm add @dax-ui/dropdownMUI and Emotion are included; the app only needs React 18 or 19.
One-time setup per app (skip if the app already uses dax-ui): install
@dax-ui/theme and wrap the app in its UIProvider.
pnpm add @dax-ui/themeUsage
import { Dropdown } from '@dax-ui/dropdown';
<Dropdown />Props
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| options (required) | readonly DropdownOption<V>[] | | The options: { value, label, description?, icon?, disabled?, group? }. |
| autocompleteProps | Partial<AutocompleteProps<DropdownOption<V>, boolean, boolean, false, "div", undefined>> | | Extra props for the MUI Autocomplete underneath, for anything not covered above (slotProps, filterOptions, autoHighlight, openOnFocus, ...). Applied last. |
| className | string | | Class name for the field's root element. |
| clearable | boolean | true | Shows a clear (×) button when there is a value. |
| clearIcon | ReactNode | | Replaces the × of the clear button. |
| colors | Partial<DropdownColors> | | Overrides any of the input, label, menu or chip colors, e.g. { chipBackground: '#4f46e5', optionSelected: '#eef2ff' }. |
| creatable | boolean | false | Lets the user add an option that isn't in the list: typing text that matches no option offers "Add “text”". Choosing it calls onCreateOption. Needs searchable. |
| defaultValue | V[] \| DropdownValue \| null | | Initial value, for an uncontrolled dropdown. |
| disableCloseOnSelect | boolean | true when multiple, else false | Keeps the menu open after choosing an option. |
| disabled | boolean | false | Disables the field. |
| error | ReactNode | false | Error state: true turns the field red and marks the control aria-invalid; a message (string or node) does that and shows the message in place of helperText. |
| fieldSlotProps | FormFieldSlotProps | | Style overrides for the label row, label, helper text and counter. |
| formatCreateLabel | ((text: string) => ReactNode) | (text) => Add “${text}”`` | Text of the "add" option in the menu. |
| fullWidth | boolean | true | Stretches the field to the full width of its container. |
| helperIcon | ReactNode | an info icon (ⓘ) | Icon before the helper or error text. Pass null to show the text without one. |
| helperText | ReactNode | | Text under the control: a hint normally. Replaced by the error message when error is a message. |
| hideLabel | boolean | false | Hides the label visually; it stays the control's accessible name. |
| id | string | | Id of the control, which the label points at. Generated when not set. |
| label | ReactNode | | Label shown above the control. Also the control's accessible name, so always set it (use hideLabel to hide it visually). |
| labelEnd | ReactNode | | Content at the far end of the label row, e.g. a "Forgot password?" link or an info tooltip. |
| labelIcon | ReactNode | | Decorative icon before the label text, e.g. <CalendarIcon />. Sized to 16px. |
| labelPlacement | "top" \| "start" | top | Where the label sits: top (above the control) or start (beside it, labelWidth wide). |
| labelWidth | string \| number | 160 | Width of the label column when labelPlacement is start. A number is px. |
| limitTags | number | -1 | Maximum number of chips shown while the field isn't focused; the rest become "+N". -1 shows all. |
| loading | boolean | false | Shows loadingText in the menu while there are no options yet. |
| loadingText | ReactNode | Loading… | Shown in the menu while loading with no options. |
| locked | boolean | false | Read-only with the disabled look (grey background). The value can't change, but the field stays focusable and readable. For values fixed after creation, e.g. "Site". |
| maxMenuHeight | number | 320 | Maximum height of the menu's list before it scrolls, in px. |
| multiple | boolean | false | Allows selecting several options, shown as removable chips. The value becomes an array. |
| name | string | | Name submitted with a form: a hidden input carries each selected value. |
| noOptionsText | ReactNode | No options | Shown in the menu when no option matches. |
| onChange | DropdownChangeHandler<V, Multiple> | | Called with the new value (an array with multiple) and the selected option(s). |
| onClose | ((event: SyntheticEvent<Element, Event>) => void) | | Called when the menu closes. |
| onCreateOption | ((text: string) => void \| DropdownOption<V>) | | Called when the user creates an option (see creatable). Return the new option to select it, e.g. after adding it to options. When it returns nothing (or isn't set), { value: text, label: text } is selected. |
| onOpen | ((event: SyntheticEvent<Element, Event>) => void) | | Called when the menu opens. |
| onSearchChange | ((search: string) => void) | | Called when the user types in the input. |
| optional | boolean | false | Adds "(optional)" after the label, for forms where most fields are required. |
| optionalText | ReactNode | (optional) | Text shown after the label when optional is set. |
| placeholder | string | | Hint shown in the empty input, e.g. "Select a department" or "Search users". |
| popupIcon | ReactNode | | Replaces the chevron that opens the menu. |
| radius | number | 12 | Corner radius of the input, in px. |
| readOnly | boolean | false | Read-only with the normal look. |
| ref | Ref<HTMLDivElement> | | Forwarded to the root element. |
| renderOption | ((option: DropdownOption<V>, state: DropdownRenderOptionState) => ReactNode) | | Renders the content of each option in the menu (the <li> around it is kept). Defaults to DropdownOptionContent: icon, label, description and a check mark. Return undefined to use the default for an option. |
| renderValue | ((value: DropdownOption<V> \| DropdownOption<V>[], getItemProps: (args: { index: number; }) => DropdownChipItemProps) => ReactNode) | | Renders the selected value(s) inside the input. With multiple, return one element per value (spread getItemProps({ index }) on each, e.g. on a DropdownChip) so limitTags works. |
| required | boolean | false | Marks the field as required: a red asterisk after the label, and aria-required on the control. |
| requiredIndicator | ReactNode | * | What marks a required label. Hidden from screen readers (the control is announced as required instead). |
| searchable | boolean | true | Lets the user type to filter the options. Off, the dropdown behaves like a <select>: click or press Enter/arrows to open, and the input can't be typed into. |
| showCheckmarks | boolean | true | Shows a check mark after selected options in the menu. |
| size | "small" \| "medium" \| "large" | medium | Input height: small (40px), medium (52px) or large (60px). Grows to fit chips. |
| startIcon | ReactNode | | Decorative icon inside the input, before the value, e.g. <SearchIcon />. |
| style | CSSProperties | | Inline styles for the field's root element. |
| sx | SxProps<Theme> | | Style overrides for the field's root element. |
| value | V[] \| DropdownValue \| null | | The selected value (an array with multiple), for a controlled dropdown. null for none. |
| variant | "filled" \| "outline" | outline | Input style: outline (surface background with a border) or filled (tinted background, no border until focused or in error). Set it for a whole app with <FieldProvider variant="filled">. |
Run pnpm docs to fill in the table above from the JSDoc in src/Dropdown.types.ts.
