Skip to main content

Components

Suggestion

Suggestion is a searchable "select" with support for multiple selections.

Suggestion is under development. If you find any errors or bugs, please report them on Github or Slack.

filter
Description

Filter options; boolean or a custom callback. See {@link Filter} for the callback signature.

Type
boolean | Filter
Default
true
creatable
Description

Allows the user to create new items

Type
boolean
Default
false
onBeforeMatch
Description

Callback when matching input value against options

Type
((event: EventBeforeMatch) => void)
name
Description

The name of the associated form control

Type
string
Default
undefined
renderSelected
Description

Change how the selected options are rendered inside the `Chip`.

Type
((args: { label: string; value: string; }) => ReactNode)
Default
({ label }) => label
multiple
Description

Allows the user to select multiple items

Type
boolean
Default
false
selected
Description

The selected item of the Suggestion. If `label` and `value` are the same, each item can be a `string`. Otherwise, each item must be a `SuggestionItem`. Using this makes the component controlled and it must be used in combination with `onSelectedChange`.

Type
string | SuggestionItem | (string | SuggestionItem)[]
defaultSelected
Description

Default selected item when uncontrolled

Type
string | SuggestionItem | (string | SuggestionItem)[]
onSelectedChange
Description

Callback when selected items changes

Type
((value: SuggestionItem) => void) | ((value: SuggestionItem[]) => void) | undefined
NameTypeDefaultDescription
filterboolean | Filtertrue

Filter options; boolean or a custom callback. See {@link Filter} for the callback signature.

creatablebooleanfalse

Allows the user to create new items

onBeforeMatch((event: EventBeforeMatch) => void)-

Callback when matching input value against options

namestringundefined

The name of the associated form control

renderSelected((args: { label: string; value: string; }) => ReactNode)({ label }) => label

Change how the selected options are rendered inside the `Chip`.

multiplebooleanfalse

Allows the user to select multiple items

selectedstring | SuggestionItem | (string | SuggestionItem)[]-

The selected item of the Suggestion. If `label` and `value` are the same, each item can be a `string`. Otherwise, each item must be a `SuggestionItem`. Using this makes the component controlled and it must be used in combination with `onSelectedChange`.

defaultSelectedstring | SuggestionItem | (string | SuggestionItem)[]-

Default selected item when uncontrolled

onSelectedChange((value: SuggestionItem) => void) | ((value: SuggestionItem[]) => void) | undefined-

Callback when selected items changes

SuggestionClear

type
Description

Specify the type of button. Unset when `asChild` is true

Type
"submit" | "reset" | "button"
Default
'button'
icon
Description

Toggle icon only styling, pass icon as children When combined with loading, the loading-icon will be shown instead of the icon.

Type
boolean
Default
false
loading
Description

Toggle loading state. Pass an element if you want to display a custom loader.

Type
ReactNode
Default
false
asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
NameTypeDefaultDescription
type"submit" | "reset" | "button"'button'

Specify the type of button. Unset when `asChild` is true

iconbooleanfalse

Toggle icon only styling, pass icon as children When combined with loading, the loading-icon will be shown instead of the icon.

loadingReactNodefalse

Toggle loading state. Pass an element if you want to display a custom loader.

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

SuggestionInput

type
Description

Supported `input` types

Type
"number" | "hidden" | "color" | "email" | "tel" | "search" | "text" | "url" | "date" | "time" | "checkbox" | "datetime-local" | "file" | "month" | "password" | "radio" | "week"
Default
'text'
size
Description

Defines the width of `Input` in count of characters.

Type
number
disabled
Description

Disables element @note Avoid using if possible for accessibility purposes

Type
boolean
readOnly
Description

Toggle `readOnly`

Type
boolean
role
Description

Set role, i.e. `switch` when `checkbox` or `radio`

Type
AriaRole
NameTypeDefaultDescription
type"number" | "hidden" | "color" | "email" | "tel" | "search" | "text" | "url" | "date" | "time" | "checkbox" | "datetime-local" | "file" | "month" | "password" | "radio" | "week"'text'

Supported `input` types

sizenumber-

Defines the width of `Input` in count of characters.

disabledboolean-

Disables element @note Avoid using if possible for accessibility purposes

readOnlyboolean-

Toggle `readOnly`

roleAriaRole-

Set role, i.e. `switch` when `checkbox` or `radio`

SuggestionList

singular
Description

The screen reader announcement for singular Suggestion, where %d is the number of Suggestions

Type
string
Default
%d forslag
plural
Description

The screen reader announcement for plural Suggestions, where %d is the number of Suggestions

Type
string
Default
%d forslag
NameTypeDefaultDescription
singularstring%d forslag

The screen reader announcement for singular Suggestion, where %d is the number of Suggestions

pluralstring%d forslag

The screen reader announcement for plural Suggestions, where %d is the number of Suggestions

Usage

Suggestion is based on u-combobox from u-elements (github.io). It is inspected by open-ui's combobox pattern (open-ui.org).

Examples

Multiple Choice

Use multiple on Suggestion. If you want to change how selected options are displayed, you can use renderSelected.

Controlled Multiple Choice

HTML

You can find general documentation on using u-combobox at u-elements: https://u-elements.github.io/u-elements/elements/u-combobox.

To get the Design System styling, add the class name ds-suggestion to the <u-combobox> element. <input> should have the ds-input class.

If you enable multiple choice, <data> should have the class name ds-chip and the data attribute data-removable="true".

CSS variables and data attributes

CSS Variables
NameValue
--dsc-suggestion-option-background--selectedvar(--ds-color-surface-tinted)
--dsc-suggestion-option-border-colorvar(--ds-color-base-default)
--dsc-suggestion-clear-gapvar(--ds-size-2)
--dsc-suggestion-clear-paddingvar(--ds-size-1)
--dsc-suggestion-clear-sizevar(--ds-size-9)
--dsc-suggestion-clear-icon-urlurl("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cpath fill='currentColor' d='M6.53 5.47a.75.75 0 0 0-1.06 1.06L10.94 12l-5.47 5.47a.75.75 0 1 0 1.06 1.06L12 13.06l5.47 5.47a.75.75 0 1 0 1.06-1.06L13.06 12l5.47-5.47a.75.75 0 0 0-1.06-1.06L12 10.94z'/%3E%3C/svg%3E")
--dsc-suggestion-option-checkmark-urlurl("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1em' height='1em' fill='none' viewBox='0 0 24 24'%3E%3Cpath fill='currentColor' fill-rule='evenodd' d='M18.998 6.94a.75.75 0 0 1 .063 1.058l-8 9a.75.75 0 0 1-1.091.032l-5-5a.75.75 0 1 1 1.06-1.06l4.438 4.437 7.471-8.405A.75.75 0 0 1 19 6.939' clip-rule='evenodd'/%3E%3C/svg%3E")
--dsc-suggestion-option-checkmark-sizevar(--ds-size-7)
--dsc-suggestion-list-gapvar(--ds-size-2)
--dsc-suggestion-border-widthvar(--ds-border-width-default)
--dsc-suggestion-border-stylesolid
--dsc-suggestion-border-colorvar(--ds-color-neutral-border-default)
--dsc-button-sizevar(--dsc-suggestion-clear-size)
Data Attributes
NameValue
data-multiplefalse
data-empty

Suggestion is based on u-combobox from u-elements (github.io). It is inspected by open-ui's combobox pattern (open-ui.org).

Edit this page on github.com (opens in a new tab)