You are viewing a PR preview for PR #1506

Agriculture Design System
Beta
Design System for the Export Service

Combobox

This component allows users to select from a list of options. It's especially useful when there are many options to choose from.

View in FigmaView in StorybookView in Github
import { ... } from '@ag.ds-next/react/combobox';

Usage

Combobox components can be imported via the combobox entrypoint in the @ag.ds-next/react package.

For example:

import { ... } from '@ag.ds-next/react/combobox';

Props

Combobox Props
PropTypeDescription
labelstringDescribes the purpose of the field.
optionsOption[]The list of options to show in the dropdown.
block?booleanIf true, the field will stretch to the fill the width of its container.
clearable?booleanIf true, the clear button will be rendered when there is a selected option.
disabled?booleanIf true, the field will not be interactive.
emptyResultsMessage?stringMessage to display when no options match the users search term.
hideOptionalLabel?booleanIf true, "(optional)" will never be appended to the label.
hint?stringProvides extra information about the field.
id?stringDefines an identifier (ID) which must be unique.
inputRef?Ref<HTMLInputElement>Ref to the input element.
invalid?booleanIf true, the invalid state will be rendered.
maxWidth?"md" | "lg" | "xl"The maximum width of the field.
message?stringMessage to show when the field is invalid.
name?stringA string specifying a name for the input control.
onBlur?FocusEventHandler<HTMLInputElement>Function to be fired following a blur event.
onChange?((value: Option | null) => void)Function to be fired following a change event.
onFocus?FocusEventHandler<HTMLInputElement>Function to be fired following a focus event.
renderItem?((item: Option, inputValue: string) => ReactNode)Used to override the default item rendering.
required?booleanIf false, "(optional)" will be appended to the label.
value?DefaultComboboxOption | nullThe value of the field.
ComboboxAsync Props
PropTypeDescription
labelstringDescribes the purpose of the field.
loadOptions(inputValue: string) => Promise<Option[]>Function to be used when options need to be loaded over the network.
block?booleanIf true, the field will stretch to the fill the width of its container.
clearable?booleanDefault: "false"If true, the clear button will be rendered when there is a selected option.
disabled?booleanIf true, the field will not be interactive.
emptyResultsMessage?stringMessage to display when no options match the users search term.
hideOptionalLabel?booleanIf true, "(optional)" will never be appended to the label.
hint?stringProvides extra information about the field.
id?stringDefines an identifier (ID) which must be unique.
inputRef?RefObject<HTMLInputElement>Ref to the input element.
invalid?booleanIf true, the invalid state will be rendered.
maxWidth?"md" | "lg" | "xl"The maximum width of the field.
message?stringMessage to show when the field is invalid.
name?stringA string specifying a name for the input control.
onBlur?FocusEventHandler<HTMLInputElement>Function to be fired following a blur event.
onChange?((value: Option | null) => void)Function to be fired following a change event.
onFocus?FocusEventHandler<HTMLInputElement>Function to be fired following a focus event.
openDropdownOnFocus?boolean@deprecated This prop is no longer being used. When true, the dropdown will open when the user focuses on the element
renderItem?((item: Option, inputValue: string) => ReactNode)Used to override the default item rendering.
required?booleanIf false, "(optional)" will be appended to the label.
showDropdownTrigger?booleanDefault: "true"If true, the dropdown trigger will be rendered.
value?DefaultComboboxOption | nullThe value of the field.
ComboboxMulti Props
PropTypeDescription
labelstringDescribes the purpose of the field.
optionsOption[]The list of options to show in the dropdown.
block?booleanIf true, the field will stretch to the fill the width of its container.
disabled?booleanIf true, the field will not be interactive.
emptyResultsMessage?stringMessage to display when no options match the users search term.
hideOptionalLabel?booleanIf true, "(optional)" will never be appended to the label.
hint?stringProvides extra information about the field.
id?stringDefines an identifier (ID) which must be unique.
inputRef?Ref<HTMLInputElement>Ref to the input element.
invalid?booleanIf true, the invalid state will be rendered.
maxWidth?"md" | "lg" | "xl"The maximum width of the field.
message?stringMessage to show when the field is invalid.
name?stringA string specifying a name for the input control.
onBlur?FocusEventHandler<HTMLInputElement>Function to be fired following a blur event.
onChange?((value: Option[]) => void)Function to be fired following a change event.
onFocus?FocusEventHandler<HTMLInputElement>Function to be fired following a focus event.
renderItem?((item: Option, inputValue: string) => ReactNode)Used to override the default item rendering.
required?booleanIf false, "(optional)" will be appended to the label.
value?Option[]The value of the field.
ComboboxAsyncMulti Props
PropTypeDescription
labelstringDescribes the purpose of the field.
loadOptions(inputValue: string) => Promise<Option[]>Function to be used when options need to be loaded over the network.
block?booleanIf true, the field will stretch to the fill the width of its container.
disabled?booleanIf true, the field will not be interactive.
emptyResultsMessage?stringMessage to display when no options match the users search term.
hideOptionalLabel?booleanIf true, "(optional)" will never be appended to the label.
hint?stringProvides extra information about the field.
id?stringDefines an identifier (ID) which must be unique.
inputRef?Ref<HTMLInputElement>Ref to the input element.
invalid?booleanIf true, the invalid state will be rendered.
maxWidth?"md" | "lg" | "xl"The maximum width of the field.
message?stringMessage to show when the field is invalid.
name?stringA string specifying a name for the input control.
onBlur?FocusEventHandler<HTMLInputElement>Function to be fired following a blur event.
onChange?((value: Option[]) => void)Function to be fired following a change event.
onFocus?FocusEventHandler<HTMLInputElement>Function to be fired following a focus event.
renderItem?((item: Option, inputValue: string) => ReactNode)Used to override the default item rendering.
required?booleanIf false, "(optional)" will be appended to the label.
value?Option[]The value of the field.
ComboboxRenderItem Props
PropTypeDescription
inputValuestringThe value of the Combobox/Autocomplete text input.
itemLabelstringThe label of the item.
beforeElement?ReactNodeUsed to add decorative elements to the end of the item such as Indicator dot or Notification badge.
endElement?ReactNodeUsed to add decorative elements to the end of the item such as Indicator dot or Notification badge.
secondaryText?ReactNodeSupporting text for the item.
tertiaryText?ReactNodeSupporting text for the item.

Source

You can view the full source code for this package on Github.