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:
import { Combobox, Form } from "@medusajs/dashboard/components"
import { useComboboxData } from "@medusajs/dashboard/hooks"
import { sdk } from "../lib/sdk"
const CollectionField = ({ control }) => {
const collections = useComboboxData({
queryKey: ["product_collections"],
queryFn: (params) =>
sdk.admin.productCollection.list(params),
getOptions: (data) =>
data.collections.map((collection) => ({
label: collection.title,
value: collection.id,
})),
})
return (
<Form.Field
control={control}
name="collection_id"
render={({ field }) => (
<Form.Item>
<Form.Label>Collection</Form.Label>
<Form.Control>
<Combobox
{...field}
options={collections.options}
searchValue={collections.searchValue}
onSearchValueChange={
collections.onSearchValueChange
}
fetchNextPage={collections.fetchNextPage}
disabled={collections.disabled}
/>
</Form.Control>
<Form.ErrorMessage />
</Form.Item>
)}
/>
)
}
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 element, accepts the following props:
Loading...
Was this page helpful?