Skip to content

Overview#

Search helps people find content. Choose Search.Input for a search field, Search.Autocomplete for suggestions as people type, or Search.Panel to combine suggestions with filters and sorting. All three keep the query on blur, have a translated screen reader label, and support the same variants, shortcut hint, and focus expansion.

Give the component a descriptive label, such as "Search products", when the search scope needs explanation. Set labelSrOnly={false} to show the label.

Import#

import { Search } from '@dnb/eufemia'
<Search.Input label="Search products" />
<Search.Autocomplete label="Search products" data={['Cards', 'Loans']} />
<Search.Panel
label="Search products"
panelDescription="Product results. Use the arrow keys to navigate results."
data={['Cards', 'Loans']}
/>

The namespace export follows List. A production bundler includes the parts you use. Search.Input uses Input and does not include Autocomplete or DrawerList. Using Search.Autocomplete or Search.Panel opts in to those dependencies. The Search.Panel implementation is excluded when you use either of the other components.

You can also import each component directly:

import SearchInput from '@dnb/eufemia/components/search/SearchInput'
import SearchAutocomplete from '@dnb/eufemia/components/search/SearchAutocomplete'
import SearchPanel from '@dnb/eufemia/components/search/SearchPanel'

Relevant links#

Behavior#

Input behavior#

Search.Input builds on Input. Use onChange to receive the query and onSubmit to search when Enter is pressed. It renders a native search input without a suggestions list. All Search components default to a Search keyboard action without autocapitalization, autocorrection, or spellcheck. Native input props can override these defaults.

Autocomplete behavior#

Search.Autocomplete builds on Autocomplete, including accessible suggestions, keyboard navigation, loading indicators, clear buttons, and asynchronous results. Provide data for local suggestions or use mode="async" and onType to load results. Use onChange to open a selected result and onSubmit to handle a query without a selected result. Selecting a result does not replace the query by default.

For a fixed or sticky header, set fixedPosition on Search.Autocomplete or popoverProps={{ fixedPosition: true }} on Search.Panel. This keeps results attached to the input while the page scrolls. Leave it disabled for inputs in normal page flow.

Panel behavior#

Search.Panel combines Autocomplete's inline results with Popover. It opens on focus when results are available and includes Popover's close button. Results render through a React portal, avoiding clipping by the input's container. The rounded panel uses the same corner radius and horizontal padding as Filter.Panel, with a 0.5rem gap below the input and space for the close button. The surface aligns with the input's left edge by default. Set align="center" or align="right" to change this; the surface stays inside the viewport. Use a render function to place filters, sorting, or actions around the provided results. These controls stay outside the listbox and retain their own keyboard behavior.

<Search.Panel
label="Search products"
panelDescription="Product results. Use the arrow keys to navigate results."
data={['Cards', 'Loans']}
>
{({ results }) => (
<Flex.Stack>
<P>Choose a product</P>
{results}
</Flex.Stack>
)}
</Search.Panel>

The results grow with their content into the available space above or below the input. The panel reserves room for custom controls, padding, and the close button, and scrolls the results when needed. It keeps its opening direction while open and updates the available height when the page scrolls or the viewport changes, including when a mobile keyboard opens. The results have a minimum height of 10rem, configurable with minHeight. This minimum is reduced when less space is available on the opening side. The panel scrolls when custom controls need more room. It closes if the opening side has less than 7rem available, keeping focus in the input. Use minHeight={0} for the natural height of a short list. Set maxHeight={16} to cap the results at 16rem. A smaller explicit maxHeight takes precedence over minHeight.

The panel defaults to a maximum width of 32rem, including the hero variant. Use popoverProps.className to customize the surface width.

Up and Down navigate results while the input has focus, and Enter selects a result. Pressing text or empty space in the panel keeps focus in the input. Tab moves between the input and custom controls without trapping focus. Escape closes the results and returns focus to the input. See the sorting and filter example.

Provide the required panelDescription in the user's language. Describe what the panel contains, including any filters, sorting, or other actions, and how to reach them. For example: "Search results include category filters and sorting. Use the arrow keys to navigate results and press Tab to reach the filters and sorting controls." The input exposes this description to screen readers even before results are available. It supplements the input's label and any existing help or status text. Autocomplete separately announces the number of available results through a live region as results change, including asynchronous updates.

For asynchronous results, use mode="async" and load data in onType, just like Search.Autocomplete. An empty panel stays closed on focus and while waiting for results. Use showIndicator() for a loading indicator inside the input. Call updateData() when results arrive, or showNoOptionsItem() for an explicit no-results message. Use showIndicatorItem() if the loading state should appear inside the panel instead. See the asynchronous examples.

Variants#

All three components accept variant="default", variant="hero" for a large input that fills its container, or variant="compact" for an input that expands on focus. Compact stays expanded while it has a query or the suggestions are open. Reduced motion preferences disable the width transition.

All variants use the theme's normal corner radius.

Set --search-width and --search-compact-width to customize the expanded and collapsed widths. Their defaults are 17.5rem and 11rem. Widths are limited to the available container. stretch fills the container in every state.

Keyboard shortcut#

Set shortcut to enable Cmd+K on Mac and Ctrl+K elsewhere and display a platform-specific hint inside the input. The shortcut leaves other focused text fields and editors alone. If several Search components enable the shortcut, the first visible, enabled input in document order receives focus. When a modal is open, the shortcut stays within that modal. Enable it on the primary search in a page. The shortcut hint is hidden on small screens and while the input has content.

When the shortcut moves focus into Search, Escape closes open results first. Press Escape again to return focus to the original control without clearing the query. An empty compact input collapses after losing focus; a query keeps it expanded.

Related components#

Search is part of the Inputs category. More components in this category:

  • Autocomplete — to help people find and choose from matching suggestions as they type.
  • Checkbox — when people can turn one or more options on or off.
  • Chip — to select compact options and filters.
  • Date picker — when people need to choose one date or a date range.
  • Dropdown — when people need to choose one option from a list.
  • Filter — to help people narrow down a list or data set.

See all in Inputs →

Demos#

Default#

Compare the three search components. Search.Input provides a search field without suggestions and supports Input's onChange and onSubmit events. Search.Autocomplete adds suggestions, while Search.Panel presents them in a flexible panel.

Autocomplete and DrawerList dependencies are excluded when only Search.Input is used in a production bundle.

Search.Input

Search.Autocomplete

Search.Panel

Use the arrow keys to navigate search results.

Compact with shortcut#

All three components expand on focus and display the shortcut inside the input. When several examples enable the shortcut, Cmd+K or Ctrl+K focuses the first visible one. The Portal header owns the shortcut on this page. Open the examples in fullscreen to try their shortcuts.

With labelSrOnly={false}, a vertical label keeps the expanded width while only the input changes width. This keeps wrapping and the input's vertical position stable.

Search.Input

Search.Autocomplete

Search.Panel

Use the arrow keys to navigate search results.

Hero#

Use the hero variant for a prominent search field, such as a home page search. It supports the same suggestions, panel, and keyboard shortcut behavior.

Search.Input

Search.Autocomplete

Search.Panel

Use the arrow keys to navigate search results.

Panel with filtering and sorting#

Use a panel when results need additional controls. This example filters by category with Chip.Group and sorts by relevance or alphabetically. The controls belong to the application, so the component also works with other filters or actions.

The required panelDescription tells screen reader users what they can find in the panel and how to reach its controls. Describe the controls your application provides and supply the text in the user's language. Result counts are announced separately.

The render function receives results, the inline Autocomplete list, and close. Keep controls outside results so they retain their own keyboard behavior. Up and Down navigate results while the input has focus, Enter selects, and Tab reaches the controls. Category chips keep focus when selected; return to the input to type a query. Escape closes the surface and returns focus to the input.

Search results include category filters and sorting. Use the arrow keys to navigate results and press Tab to reach the filters and sorting controls.

Select a result to try the search.

Asynchronous results#

Both Search.Autocomplete and Search.Panel support mode="async". These examples simulate a delayed response with Autocomplete's managed debounce method. Focusing an empty input keeps the results closed. The input shows a loading indicator while waiting, then opens the results or an explicit no-results message. Clearing the query closes the results and cancels the pending response.

The onType callback receives the same result and loading methods as Autocomplete. For remote results, see loading data asynchronously. Ignore outdated responses when a newer query is typed or the input is cleared.

Search results appear after typing. Use the arrow keys to navigate results.
Suggest an edit
Eufemia · /web/components/search/ · Version 11.19.0