Skip to main content

What are you looking for?

Try searching for…

Components

Search

Search allows users to quickly find relevant content on a website or in an application. The component consists of a search field, with or without a search button.

Search is deprecated and will be removed in the next major version. Read Search is being removed, what should you do? to see how you can make your own search field.

Press Enter to start editing
<input class="ds-input" type="search" aria-label="Search"/>
const PreviewEn = () => {
  return <Input type='search' aria-label='Search' />;
};

render(<PreviewEn />)

Usage

Use the class name ds-suggestion on a <ds-suggestion> around <input>. If you want a clear button, add a <button type="reset"> after the <input>. It is automatically shown and hidden based on the input's value.

You can change the variant on the button to adjust its appearance. The magnifying icon is shown when input has type="search", and hidden when input has type="text".

CSS variables and data attributes

Sizes are controlled with data-size and colors with data-color. The component will inherit from the closest parent where these are set.

CSS Variables
NameValue
--dsc-button-sizevar(--dsc-suggestion-clear-size)
--dsc-search-clear-icon-urlvar(--dsc-suggestion-clear-icon-url)
--dsc-search-clear-paddingvar(--dsc-suggestion-clear-padding)
--dsc-search-clear-sizevar(--dsc-suggestion-clear-size)
--dsc-search-magnifying-icon-sizevar(--dsc-suggestion-search-icon-size)
--dsc-search-magnifying-icon-urlvar(--dsc-suggestion-search-icon-url)
--dsc-search-padding-inlinevar(--dsc-suggestion-clear-gap)
--dsc-suggestion-border-colorvar(--ds-color-neutral-border-subtle)
--dsc-suggestion-border-stylesolid
--dsc-suggestion-border-widthvar(--ds-border-width-default)
--dsc-suggestion-chip-backgroundvar(--ds-color-base-default)
--dsc-suggestion-chip-background--hovervar(--ds-color-base-hover)
--dsc-suggestion-chip-border-colortransparent
--dsc-suggestion-chip-border-radiusvar(--ds-border-radius-full)
--dsc-suggestion-chip-border-stylesolid
--dsc-suggestion-chip-border-widthvar(--ds-border-width-default)
--dsc-suggestion-chip-colorvar(--ds-color-base-contrast-default)
--dsc-suggestion-chip-font-sizevar(--ds-body-sm-font-size)
--dsc-suggestion-chip-gapvar(--ds-size-1)
--dsc-suggestion-chip-heightvar(--ds-size-8)
--dsc-suggestion-chip-icon-sizevar(--ds-icon-size)
--dsc-suggestion-chip-icon-urlurl("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1em' height='1em' fill='none' viewBox='0 0 24 24' focusable='false' role='img'%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/path%3E%3C/svg%3E")
--dsc-suggestion-chip-input-sizevar(--ds-size-5)
--dsc-suggestion-chip-padding0 var(--ds-size-3)
--dsc-suggestion-chip-spacingcalc(.5 * (var(--dsc-suggestion-chip-height) - var(--dsc-suggestion-chip-input-size)))
--dsc-suggestion-clear-background--activevar(--ds-color-surface-active)
--dsc-suggestion-clear-background--hovervar(--ds-color-surface-hover)
--dsc-suggestion-clear-border-radiusvar(--ds-border-radius-md)
--dsc-suggestion-clear-gapvar(--ds-size-2)
--dsc-suggestion-clear-icon-urlurl("data:image/svg+xml,%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-clear-paddingvar(--ds-size-1)
--dsc-suggestion-clear-sizevar(--ds-size-9)
--dsc-suggestion-create-icon-urlurl("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M12.75 5.5a.75.75 0 0 0-1.5 0v5.75H5.5a.75.75 0 0 0 0 1.5h5.75v5.75a.75.75 0 0 0 1.5 0v-5.75h5.75a.75.75 0 0 0 0-1.5h-5.75z'/%3E%3C/svg%3E")
--dsc-suggestion-create-text'Legg til "{value}"'
--dsc-suggestion-empty-text"Tomt"
--dsc-suggestion-list-backgroundvar(--ds-color-neutral-surface-default)
--dsc-suggestion-list-border-radiusvar(--ds-border-radius-md)
--dsc-suggestion-list-box-shadowvar(--ds-shadow-md)
--dsc-suggestion-list-colorvar(--ds-color-text-default)
--dsc-suggestion-list-gapvar(--ds-size-1)
--dsc-suggestion-list-offsetvar(--ds-size-1)
--dsc-suggestion-list-paddingvar(--ds-size-3) var(--ds-size-2)
--dsc-suggestion-list-placementbottom
--dsc-suggestion-option-background--hovervar(--ds-color-surface-hover)
--dsc-suggestion-option-background--selectedvar(--ds-color-surface-active)
--dsc-suggestion-option-border-radiusvar(--ds-border-radius-md)
--dsc-suggestion-option-checkmark-bordercalc(max(2px, .125rem))
--dsc-suggestion-option-checkmark-border-colorvar(--ds-color-neutral-border-default)
--dsc-suggestion-option-checkmark-sizevar(--ds-size-6)
--dsc-suggestion-option-checkmark-urlurl("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%221em%22%20height%3D%221em%22%20fill%3D%22none%22%20viewBox%3D%220%200%2024%2024%22%20focusable%3D%22false%22%20role%3D%22img%22%3E%3Cpath%20fill%3D%22currentColor%22%20fill-rule%3D%22evenodd%22%20d%3D%22M18.998%206.94a.75.75%200%200%201%20.063%201.058l-8%209a.75.75%200%200%201-1.091.032l-5-5a.75.75%200%201%201%201.06-1.06l4.438%204.437%207.471-8.405A.75.75%200%200%201%2019%206.939%22%20clip-rule%3D%22evenodd%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E")
--dsc-suggestion-option-gapvar(--ds-size-2)
--dsc-suggestion-option-paddingvar(--ds-size-3)
--dsc-suggestion-search-icon-sizevar(--ds-icon-size)
--dsc-suggestion-search-icon-spacingvar(--ds-size-3)
--dsc-suggestion-search-icon-urlurl("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cpath d='M10.5 3.25a7.25 7.25 0 1 0 4.57 12.88l5.41 5.41a.75.75 0 1 0 1.06-1.06l-5.41-5.41A7.25 7.25 0 0 0 10.5 3.25M4.75 10.5a5.75 5.75 0 1 1 11.5 0 5.75 5.75 0 0 1-11.5 0'/%3E%3C/svg%3E")
--dsc-suggestion-sr-added"La til"
--dsc-suggestion-sr-clear"Fjern tekst"
--dsc-suggestion-sr-empty"Ingen valgte"
--dsc-suggestion-sr-found"Naviger til venstre for å finne %d valgte"
--dsc-suggestion-sr-invalid"Ugyldig valg"
--dsc-suggestion-sr-items"Valgte"
--dsc-suggestion-sr-of"av"
--dsc-suggestion-sr-plural"%d forslag"
--dsc-suggestion-sr-remove"Trykk for å fjerne"
--dsc-suggestion-sr-removed"Fjernet"
--dsc-suggestion-sr-singular"%d forslag"
--dsc-suggestion-sr-toggle"Forslag"
--dsc-suggestion-toggle-icon-urlurl("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5.97 9.47a.75.75 0 0 1 1.06 0L12 14.44l4.97-4.97a.75.75 0 1 1 1.06 1.06l-5.5 5.5a.75.75 0 0 1-1.06 0l-5.5-5.5a.75.75 0 0 1 0-1.06'/%3E%3C/svg%3E")
Data Attributes
NameValue
data-activedescendant
data-creatable
data-empty
data-multiple
data-overscrollcontain

Examples

With Input

In most cases, an Input with type="search" in a Field is enough.

With label

If you want a label on the search field, add a label that you connect with Suggestion.Input. In the example, we have used Field to connect the label and Suggestion.Input.

<form>

React

Search is deprecated and will be removed in the next major version. Use Input with type="search" in a Field instead, or Suggestion if you need a clear button.

SearchButton

variant
Description

Specify which variant to use

Type
"primary" | "secondary" | "tertiary"
Default
'primary'
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
type
Description

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

Type
"button" | "submit" | "reset"
Default
'button'
NameTypeDefaultDescription
variant"primary" | "secondary" | "tertiary"'primary'

Specify which variant to use

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.

type"button" | "submit" | "reset"'button'

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

SearchClear

aria-label
Description

Aria label for the clear button @deprecated Please use `--dsc-suggestion-sr-clear` or `data-sr-clear` on Suggestion to set label.

Type
string
NameTypeDefaultDescription
aria-labelstring-

Aria label for the clear button @deprecated Please use `--dsc-suggestion-sr-clear` or `data-sr-clear` on Suggestion to set label.

SearchInput

type
Description

Type of input, affects if magnifying glass is shown or not. Use 'text' to hide magnifying glass.

Type
"text" | "search"
Default
search
NameTypeDefaultDescription
type"text" | "search"search

Type of input, affects if magnifying glass is shown or not. Use 'text' to hide magnifying glass.

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