Combobox

ComboBox component is a form element that allows the user to select one option from a list of options.

Design system docs

Examples Default combobox

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 with manual input

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>
Remote data

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

Importing
import { DapDSCombobox } from 'dap-design-system/dist/dds'
Importing React
import { DapDSComboboxReact } from 'dap-design-system/dist/react'
Slots

No slots available.

Attributes
PropertyTypeDefaultDescription
valuestringThe value of the select.
placeholderstringThe 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'.
openedbooleanWhether 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'.
labelstringThe label of the select.
descriptionstringThe description of the select.
tooltipstringThe tooltip of the select.
size'sm' 'lg'The size of the select. Default is 'md'.
disabledbooleanWhether the select is disabled.
requiredbooleanWhether the select is required.
readonlybooleanWhether the select is readonly.
autofocusbooleanWhether the select is autofocus.
feedbackstringThe 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.
openOnEmptybooleanWhether the combobox should open on empty results.
allowManualInputbooleanWhether the combobox allows manual input, or free text.
searchForTextbooleanWhether the combobox should search for the selected item text.
noTextCompletebooleanWhether the combobox should not complete the text.
searchButtonAriaLabelstringThe aria label of the search button.
selectablebooleanShow the selected item check mark in the dropdown.
noAnimationbooleanWhether the combobox open indicator should be animated.
Events
Event NameDescription
dds-changeFired when the select value changes.
dds-blurEmitted when the select loses focus.
dds-focusEmitted when the select gains focus.
dds-clearEmitted when the select is cleared.
dds-searchEmitted when the manual input value changes.
CSS Parts
Part NameDescription
baseThe main select container.
triggerThe trigger button of the select.
labelThe label of the select.
descriptionThe description of the select.
feedbackThe feedback of the select.
tooltipThe tooltip of the select.
option-listThe option list of the select.