Combobox - Admin Components
Note: This component is available since Medusa v2.21.0.
The Combobox component is a select input with search, multi-select, pagination, and the option to create new values. The Medusa Admin uses it in forms where the user chooses records loaded from the Medusa backend, such as a product's collection or a region's payment providers.
Example#
Pair Combobox with the useComboboxData hook to load the options from the Medusa backend and paginate them as the user scrolls:
1import { Combobox, Form } from "@medusajs/dashboard/components"2import { useComboboxData } from "@medusajs/dashboard/hooks"3import { sdk } from "../lib/sdk"4 5const CollectionField = ({ control }) => {6 const collections = useComboboxData({7 queryKey: ["product_collections"],8 queryFn: (params) =>9 sdk.admin.productCollection.list(params),10 getOptions: (data) =>11 data.collections.map((collection) => ({12 label: collection.title,13 value: collection.id,14 })),15 })16 17 return (18 <Form.Field19 control={control}20 name="collection_id"21 render={({ field }) => (22 <Form.Item>23 <Form.Label>Collection</Form.Label>24 <Form.Control>25 <Combobox26 {...field}27 options={collections.options}28 searchValue={collections.searchValue}29 onSearchValueChange={30 collections.onSearchValueChange31 }32 fetchNextPage={collections.fetchNextPage}33 disabled={collections.disabled}34 />35 </Form.Control>36 <Form.ErrorMessage />37 </Form.Item>38 )}39 />40 )41}
To let the user select multiple values, pass an array as the value prop. The onChange function then receives an array of the selected values.
Props#
Aside from the HTML props of an input element, Combobox accepts the following props:
Loading...
Was this page helpful?