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>
Sizes
<dap-ds-stack>
<dap-ds-combobox 
label="Xs Fruits"
size="xs"
placeholder="Favorite fruit"
description="Select your favorite fruit"
feedback="This is a feedback message"
feedbacktype="negative"
>
<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>

<dap-ds-combobox 
label="Sm Fruits"
size="sm"
placeholder="Favorite fruit"
description="Select your favorite fruit"
feedback="This is a feedback message"
feedbacktype="negative"
>
<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>

<dap-ds-combobox 
label="Lg Fruits"
size="lg"
placeholder="Favorite fruit"
description="Select your favorite fruit"
feedback="This is a feedback message"
feedbacktype="negative"
>
<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>
</dap-ds-stack>
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'
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.
tooltipPlacement'top', 'right' , 'bottom' , 'left'The tooltip placement of the input.
size'xs', 'sm' , 'sm'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.
Slots
NameDescription
(default)The default slot for the options.
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.
dds-inputEmitted when typing happens in the input.
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.
CSS Custom Properties
Property NameDescription
--dds-combobox-backgroundThe background color of the combobox. Defaults to var(--dds-fields-background-default).
--dds-combobox-border-colorThe border color of the combobox. Defaults to var(--dds-border-neutral-base).
--dds-combobox-border-widthThe border width of the combobox. Defaults to var(--dds-border-width-base, 1px).
--dds-combobox-border-radiusThe border radius of the combobox. Defaults to var(--dds-radius-base).
--dds-combobox-text-colorThe text color of the combobox. Defaults to var(--dds-text-neutral-base).
--dds-combobox-placeholder-colorThe placeholder text color. Defaults to var(--dds-text-neutral-subtle).
--dds-combobox-disabled-backgroundThe background color when disabled. Defaults to var(--dds-background-neutral-stronger).
--dds-combobox-disabled-textThe text color when disabled. Defaults to var(--dds-text-neutral-disabled).
--dds-combobox-error-borderThe border color for error state. Defaults to var(--dds-border-negative-base).
--dds-combobox-success-borderThe border color for success state. Defaults to var(--dds-border-positive-base).
--dds-combobox-icon-colorThe color of the icons. Defaults to var(--dds-text-icon-neutral-subtle).
--dds-combobox-clear-icon-colorThe color of the clear icon. Defaults to var(--dds-button-subtle-icon-neutral-enabled).
--dds-combobox-popup-backgroundThe background color of the popup. Defaults to var(--dds-background-neutral-subtle).
--dds-combobox-popup-shadowThe box shadow of the popup. Defaults to 0 4px 6px -1px rgb(0 0 0 / 8%), 0 2px 4px -1px rgb(0 0 0 / 6%).
--dds-combobox-padding-xsThe padding for extra small size. Defaults to var(--dds-spacing-200).
--dds-combobox-padding-smThe padding for small size. Defaults to var(--dds-spacing-200).
--dds-combobox-padding-lgThe padding for large size. Defaults to var(--dds-spacing-300).
--dds-combobox-padding-horizontalThe horizontal padding. Defaults to var(--dds-spacing-300).
--dds-combobox-padding-verticalThe vertical padding. Defaults to var(--dds-spacing-200).
--dds-combobox-gapThe gap between elements. Defaults to var(--dds-spacing-100).
--dds-combobox-icon-gapThe gap between icons. Defaults to var(--dds-spacing-200).
--dds-combobox-action-gapThe gap between action elements. Defaults to var(--dds-spacing-200).
--dds-combobox-action-paddingThe padding for action elements. Defaults to var(--dds-spacing-300).
--dds-combobox-clear-icon-widthThe width of the clear icon. Defaults to var(--dds-spacing-800).
--dds-combobox-dropdown-icon-rightThe right position of the dropdown icon. Defaults to var(--dds-spacing-600).
--dds-combobox-min-widthThe minimum width of the combobox. Defaults to 7.5rem.