ComboBox component is a form element that allows the user to select one option from a list of options.
Design system docs
The default combobox is a select element with a label, placeholder, and description. The dap-ds-option-item
elements should be placed inside the root component.
By default the combobox autocomplete the options.
<dap-ds-combobox label="Fruits" placeholder="Favorite fruit" description="Select your favorite fruit" > <dap-ds-option-item value="alma">Apple</dap-ds-option-item> <dap-ds-option-item value="korte">Pear</dap-ds-option-item> <dap-ds-option-item value="szilva">Plum</dap-ds-option-item> <dap-ds-option-item value="barack">Peach</dap-ds-option-item> <dap-ds-option-item value="szolo">Grape</dap-ds-option-item> <dap-ds-option-item value="meggy">Sour cherry</dap-ds-option-item> <dap-ds-option-item value="cseresznye">Cherry</dap-ds-option-item> </dap-ds-combobox>
Combobox field can have free text functionality. With this feature, the user can type in any text, not just the predefined options.
You have to listen for the dds-search
event to get the input value.
<dap-ds-combobox allowManualInput label="Fruits" placeholder="Favorite fruit" description="Select your favorite fruit" > <dap-ds-option-item value="alma">Apple</dap-ds-option-item> <dap-ds-option-item value="korte">Pear</dap-ds-option-item> <dap-ds-option-item value="szilva">Plum</dap-ds-option-item> <dap-ds-option-item value="barack">Peach</dap-ds-option-item> <dap-ds-option-item value="szolo">Grape</dap-ds-option-item> <dap-ds-option-item value="meggy">Sour cherry</dap-ds-option-item> <dap-ds-option-item value="cseresznye">Cherry</dap-ds-option-item> </dap-ds-combobox>
ComboBox field can be used to fetch data from a remote server. For remote search and autocomplete use the dap-ds-search
component.
JS
// Show the loading indicator
combobox.loading = true
fetch(`'https://dummyjson.com/todos'`)
.then(res => res.json())
.then(data => {
// Clear the previous options
combobox.innerHTML = ''
// Add the new options
data?.todos.forEach(item => {
const option = document.createElement('dap-ds-option-item')
option.value = item.id.toString()
option.appendChild(document.createTextNode(item.todo))
combobox.appendChild(option)
})
// Hide the loading indicator
combobox.loading = false
})
})
React
import { useEffect, useRef, useState } from 'react'
const Combobox = () => {
const [filterResult, setFilterResult] = useState<any[]>([])
const searchRef = useRef(null)
useEffect(() => {
if (searchRef.current) {
fetch('https://dummyjson.com/todos')
.then(res => res.json())
.then(data => {
setFilterResult(data.todos)
})
}
}, [])
return (
<dap-ds-combobox
label="Todos"
ref={searchRef}
sync
placeholder={'Add some todos for your happy life'}>
{filterResult?.map(item => (
<dap-ds-option-item
key={item.id}
value={item.id}
label={item.todo}>
{item.todo}
</dap-ds-option-item>
))}
</dap-ds-combobox>
)
}
export default Combobox
import { DapDSCombobox } from 'dap-design-system/dist/dds'
import { DapDSComboboxReact } from 'dap-design-system/dist/react'
No slots available.
Property | Type | Default | Description |
---|---|---|---|
value | string | The value of the select. | |
placeholder | string | The placeholder of the select. | |
placement | 'top' 'top-start' 'top-end' 'right' 'right-start' 'right-end' 'bottom' 'bottom-start' 'bottom-end' 'left' 'left-start' 'left-end' | The placement of the select dropdown. Default is 'bottom-start'. | |
opened | boolean | Whether the select dropdown is opened. | |
sync | 'width' 'height' 'both' | The sync mode of the select dropdown. How the dropdown item size is synced to the trigger element'. | |
label | string | The label of the select. | |
description | string | The description of the select. | |
tooltip | string | The tooltip of the select. | |
size | 'sm' 'lg' | The size of the select. Default is 'md'. | |
disabled | boolean | Whether the select is disabled. | |
required | boolean | Whether the select is required. | |
readonly | boolean | Whether the select is readonly. | |
autofocus | boolean | Whether the select is autofocus. | |
feedback | string | The feedback content of the select. | |
feedbackType | 'error' 'warning' 'info' | The feedback type of the select. | |
searchMode | 'none' 'typehead' 'autocomplete' 'manual' | The search mode of the select. | |
openOnEmpty | boolean | Whether the combobox should open on empty results. | |
allowManualInput | boolean | Whether the combobox allows manual input, or free text. | |
searchForText | boolean | Whether the combobox should search for the selected item text. | |
noTextComplete | boolean | Whether the combobox should not complete the text. | |
searchButtonAriaLabel | string | The aria label of the search button. | |
selectable | boolean | Show the selected item check mark in the dropdown. | |
noAnimation | boolean | Whether the combobox open indicator should be animated. |
Event Name | Description |
---|---|
dds-change | Fired when the select value changes. |
dds-blur | Emitted when the select loses focus. |
dds-focus | Emitted when the select gains focus. |
dds-clear | Emitted when the select is cleared. |
dds-search | Emitted when the manual input value changes. |
Part Name | Description |
---|---|
base | The main select container. |
trigger | The trigger button of the select. |
label | The label of the select. |
description | The description of the select. |
feedback | The feedback of the select. |
tooltip | The tooltip of the select. |
option-list | The option list of the select. |