Combobox
A feature-rich dropdown component that supports search filtering, async data loading, and multi-select. Used internally by RenderFormFields for ColumnTypeEnum.SELECT and ColumnTypeEnum.MANY_TO_MANY fields.
Import
import { Combobox } from "@phpcreation/frontend-components-react-nextjs-bundle/components/Combobox";Props
| Prop | Type | Default | Description |
|---|---|---|---|
options | { value: string; label: string }[] | [] | Static options list |
value | string | string[] | — | Controlled value |
onChange | (value: string | string[]) => void | — | Change handler |
placeholder | string | "Select..." | Placeholder text |
isMulti | boolean | false | Enable multi-select |
isAsync | boolean | false | Enable async loading |
loadOptions | (query: string) => Promise<Option[]> | — | Async loader function |
disabled | boolean | false | Disable the control |
className | string | — | Additional CSS classes |
Usage
Static
import { Combobox } from "...";
const statusOptions = [
{ value: "draft", label: "Draft" },
{ value: "pending", label: "Pending" },
{ value: "paid", label: "Paid" },
];
<Combobox
options={statusOptions}
value={status}
onChange={setStatus}
placeholder="Select status..."
/>In CRUD forms, RenderFormFields automatically renders Combobox for ColumnTypeEnum.SELECT (with isAsync) and ColumnTypeEnum.MANY_TO_MANY (with isMulti). You only need to use this directly for custom form layouts.
In CRUD Forms
When RenderFormFields renders a SELECT or MANY_TO_MANY field, the Combobox receives:
loadOptions— derived from the field’soptionsUrloroptionsArrayisMulti—trueforMANY_TO_MANYrelationsisAsync—truewhenoptionsUrlis set
To use a static options array instead of an API call, set optionsArrayFinite in changes.json:
{
"fields": {
"status": {
"optionsArrayFinite": "statusOptionsArray"
}
}
}Related
- Select — simple static dropdown (no search)
- Select Async — async without search
- Render Form Fields
- Form (RHF)
Last updated on