Properties#
You may check out the DrawerList Properties down below as well as the Data structure examples.
| Type | Description | |
|---|---|---|
mode | "sync" "async" | (optional) If set to async, it prevents showing the "no options" message during typing / filtering. Defaults to sync. |
inputValue | string | (optional) Lets you define a custom input value. Setting it to an empty string "" will reset the input value. |
placeholder | string | (optional) Use this to define the pre-filled placeholder text in the input. Defaults to title="Skriv og velg". |
title | React.ReactNode | (optional) Give a title to let the user know what they have to do. Defaults to Skriv og velg. |
search | SearchOptions | (optional) Configure search behavior with a single config object. An object with optional keys: filter (enable result filtering, default true), reorder (enable relevance reordering, default true), highlight (enable text highlighting, default true), numbers (enable number search, default false), matchInsideWordsFrom (threshold for in-word search, default 3), and match (matching mode "word" or "starts-with", default "word"). Example: search={{ filter: false }} to disable filtering while keeping highlighting. |
disableFilter | boolean | (deprecated) If set to true, word highlighting will still be active, but no options will be filtered out. Defaults to false. Deprecated: Use search={{ filter: false }} instead. |
disableHighlighting | boolean | (deprecated) If set to true, word highlighting will be disabled, but the options will still get filtered. Defaults to false. Deprecated: Use search={{ highlight: false }} instead. |
disableReorder | boolean | (deprecated) If set to true, reordering of search results will be disabled. Defaults to false. Deprecated: Use search={{ reorder: false }} instead. |
searchNumbers | boolean | (deprecated) If set to true and searchInWordIndex is not set, the user will be able to more easily search and filter e.g. bank account numbers. Defaults to false. Deprecated: Use search={{ numbers: true }} instead. |
searchInWordIndex | string number | (deprecated) This gives you the possibility to change the threshold number, which defines from what word on we search "inside words". Defaults to 3. Deprecated: Use search={{ matchInsideWordsFrom: number }} instead. |
searchMatch | "word" "starts-with" | (deprecated) Defines how search matching is performed. Use starts-with to only match items that begin with the first typed word. Defaults to word. Deprecated: Use search={{ match: "word" | "starts-with" }} instead. |
keepValue | boolean | (optional) Use true to not remove the typed value on input blur, if it is invalid. By default, the typed value will disappear / be replaced by a selected value from the data list during the input field blur. Defaults to false. |
keepSelection | boolean | (optional) Use true to not remove selected item on input blur, when the input value is empty. Defaults to false. |
keepValueAndSelection | boolean | (optional) Like keepValue – but would not reset to the selected value during input field blur. Also, the selected value would still be kept. Defaults to false. |
preventSelection | boolean | (optional) If set to true, no permanent selection will be made. Also, the typed value will not disappear on input blur (like keepValue). Defaults to false. |
showClearButton | boolean | (optional) If set to true, a clear button is shown inside the input field. Defaults to false. |
icon | string React.ReactNode | (optional) To be included in the autocomplete input. Defaults to loupe. Set to null to remove the icon entirely – no progress indicator will then be shown while loading. |
iconSize | string | (optional) Change the size of the icon programmatically. |
iconPosition | "left" "right" | (optional) Position of the icon inside the autocomplete. Set to left or right. Defaults to left. |
size | "small" "default" "medium" "large" | (optional) Define the height of the Autocomplete. Can be set to small, default, medium and large. Defaults to default. |
drawerClass | string | (optional) Define a custom class for the internal drawer-list. This makes it possible more easily customize the drawer-list style with styled-components and the css style method. Defaults to null. |
showSubmitButton | boolean | (optional) Use true to show an Autocomplete button to toggle the DrawerList. Defaults to false. |
align | "left" "right" | (optional) Use right to change the options alignment direction. Defaults to left. |
noOptions | React.ReactNode | (optional) Text shown in the "no options" item. If set to false, the list will not be rendered when there are no options available. Defaults to Ingen alternativer. |
ariaLiveOptions | React.ReactNode | (optional) Text read out by screen readers. This way users with screen readers know how many options they got during typing. Defaults to %s alternativer. |
showAll | React.ReactNode | (optional) Text that lets a user unravel all the available options. Defaults to Vis alt. |
indicatorLabel | React.ReactNode | (optional) Text shown on indicator "options" item. Defaults to Henter data .... |
showOptionsSr | string | (optional) Only for screen readers. Title of the button to show the suggestions / options. It is always present and when activating, it opens the DrawerList and sets the focus on it. Defaults to Bla gjennom alternativer, lukk med esc knappen. |
selectedSr | string | (optional) Only for screen readers (VoiceOver). The label used to announce the selected item. Defaults to Valgt:. |
selectAll | boolean | (optional) If set to true, then the whole input value gets selected on the entry focus. A second click will place the cursor on the wanted position. |
submitButtonTitle | React.ReactNode | (optional) Title on submit button. Defaults to Vis alternativer. |
submitButtonIcon | string React.Element | (optional) The icon used in the submit button. Defaults to chevron_down. |
submitElement | React.ReactNode | (optional) Replace the dropdown / submit button with a custom React element. Defaults to the input SubmitButton import { SubmitButton } from '@dnb/eufemia/components/input/Input'. |
open | boolean | (optional) If set to true, the Autocomplete will be rendered initially with a visible and accessible data list / options. |
openOnFocus | boolean | (optional) Use true to auto open the list once the user is entering the input field with the keyboard. |
stretch | boolean | (optional) If set to true, then the autocomplete will be 100% in available width. |
skipPortal | boolean | (optional) Set to true to disable the React Portal behavior. Defaults to false. |
inline | boolean | (optional) Use true to render the results list persistently open in normal document flow, instead of an overlay. The toggle button is hidden. Defaults to false. |
status | "error" "information" boolean | (optional) Text with a status message. The style defaults to an error message. You can use true to only get the status color, without a message. |
statusState | "error" "information" | (optional) Defines the state of the status. Currently, there are two statuses [error, information]. Defaults to error. |
statusProps | object | (optional) Use an object to define additional FormStatus properties. |
globalStatus | object | (optional) The configuration used for the target GlobalStatus. |
label | React.ReactNode | (optional) Prepends the Form Label component. If no ID is provided, a random ID is created. |
labelDirection | "horizontal" "vertical" | (optional) Use labelDirection="horizontal" to change the label layout direction. Defaults to vertical. |
labelSrOnly | boolean | (optional) Use true to make the label only readable by screen readers. |
suffix | React.ReactNode | (optional) Text describing the content of the Autocomplete more than the label. You can also send in a React component, so it gets wrapped inside the Autocomplete component. |
skeleton | boolean | (optional) If set to true, an overlaying skeleton with animation will be shown. |
inputRef | React.RefObject | (optional) Use a React.Ref to get access to the input DOM element. |
inputElement | string React.Element | (optional) Lets you provide a custom React element as the input HTML element. |
DrawerList | Various | (optional) All DrawerList properties. |
Space | string object | (optional) Spacing properties like top or bottom are supported. |
DrawerList Properties#
| Type | Description | |
|---|---|---|
data | {DATA} () => {DATA} | (required) The data we want to fill the list with. Details on the type of {DATA} can be found below. The data can be provided as an array or object. Or as a function that returns the data (called when user opens the list). |
groups | Array<React.ReactNode> | (optional) An array of group titles for the list items. Only the first group can be undefined. |
value | string number | (optional) Define a preselected data entry. In order of priority, value can be set to: object key (if data is an object), selectedKey property (if data is an array), array index (if no selectedKey) or content (if value is a non-integer string). |
defaultValue | number | (optional) Define a startup value or handle a re-render without handling the state during the re-render by yourself. Defaults to null. |
noDivider | boolean | (optional) Removes the divider line between options. Defaults to false. |
direction | "auto" "top" "bottom" | (optional) Defines the direction of how the drawer-list shows the options list. Can be bottom or top. Defaults to auto. |
preventSelection | boolean | (optional) If set to true, the DrawerList will then not make any permanent selection. |
focusable | boolean | (optional) If set to true, the element is then focusable by assertive technologies. |
preventClose | boolean | (optional) If set to true, the DrawerList will not close on any events. |
keepOpen | boolean | (optional) If set to true, the DrawerList will close on outside clicks, but not on selection. |
independentWidth | boolean | (optional) If set to true, the DrawerList will handle its width and position independently of the parent element. |
fixedPosition | boolean | (optional) If set to true, the DrawerList will be fixed in its scroll position by using CSS position: fixed;. |
enableBodyLock | boolean | (optional) If set to true, the HTML body will get locked from scrolling when the Dropdown is open. |
skipKeysearch | boolean | (optional) If set to true, search items by the first key will be ignored. |
ignoreEvents | boolean | (optional) If set to true, all keyboard and mouse events will be ignored. |
alignDrawer | string | (optional) Use 'right' to change the options alignment direction. Only makes sense to use in combination with preventSelection - or if an independent width is used. |
listClass | string | (optional) Define an HTML class that will be set on the list, alongside dnb-drawer-list__list. |
portalClass | string | (optional) Define an HTML class that will be set on the DOM portal alongside dnb-drawer-list__portal__style. Can be useful to handle e.g. a custom z-index in relation to a header. |
scrollable | boolean | (optional) Defines if the options list should be scrollable (the max-height is set by default to 50vh). |
noScrollAnimation | boolean | (optional) To disable scrolling animation. |
noAnimation | boolean | (optional) To disable appear/disappear (show/hide) animation. |
skipPortal | boolean | (optional) To disable the React Portal behavior. |
inline | boolean | (optional) If set to true, the list is rendered in normal document flow instead of an absolute overlay, with a flat look instead of a floating card. Implies skipPortal. Defaults to false. |
minHeight | string | (optional) Defines the minimum height (in rem) of the options list. |
maxHeight | string | (optional) Defines the maximum height (in rem) of the options list. |
pageOffset | string | (optional) Defines the available scrollable height. If scrolling should not change the height of the drawer-list, then set it to 0 (useful if the DrawerList is used in fixed positions in contrast to a scrollable page content). |
observerElement | string | (optional) Set an HTML element, either as a selector or a DOM element. Can be used to send in an element which will be used to make the direction calculation on. |
cacheHash | string | (optional) Set a cacheHash as a string to enable internal memorizing of the list to enhance rerendering performance. Components like Autocomplete are using this because of the huge data changes due to search and reorder. |
wrapperElement | string HTMLElement | (optional) Has to be an HTML Element, or a selector for one, ideally a parent element, used to calculate sizes and distances. Also used for the 'click outside' detection. Clicking on the wrapperElement will not trigger an outside click. |
optionsRender | function | (optional) Has to be a function, returning the items again. See example. This can be used to add additional options above the actual rendered list. |
listDriver | DrawerListDriver | (optional) Opt in to a custom list renderer. Use createDrawerListVirtualization from @dnb/eufemia/fragments/drawer-list/Virtualization to render large data sets without mounting every option. Install the optional @tanstack/react-virtual peer dependency when using this driver. Cannot be combined with optionsRender. |
Space | string object | (optional) Spacing properties like top or bottom are supported. |
arrowPosition | string | (deprecated) Does nothing as there is no longer any arrow. Legacy docs: Position of the arrow on the popup drawer. Set to left or right. Defaults to left if not set. |
The data property#
The data can be structured in two main ways:
- As an array
- As an object.
An array is preferred as it gives you the most options.
data as an array#
// an array can contain complex items and offers the most controlconst data = [{content: "Item 1",},{content: <span>Item 2</span>},{content: ["Item 3", "Line 2", <span>Line 3</span>]},{content: ['Main account', '1234 12 12345'],selectedValue: 'Main account (605,22 kr)',suffixValue: '605,22 kr',},{content: ['Old account', <i>Closed</i>],disabled: true,suffixValue: '0,00 kr',},]// If you only use the `content` property, you can use it directly in the array.// This list is identical to the one above:const data = ["Item 1",<span>Item 2</span>,["Item 3", "Line 2", <span>Line 3</span>],{content: ['Main account', '1234 12 12345'],selectedValue: 'Main account (605,22 kr)',suffixValue: '605,22 kr',},{content: ['Old account', <i>Closed</i>],disabled: true,suffixValue: '0,00 kr',},]const onChange = ({ data, value }) => {console.log(data) // returns the item as it appears in the arrayconsole.log(value) // returns the index of the item}
Each object in the array have the following properties:
| Type | Description | |
|---|---|---|
content | string React.ReactNode Array<(string | React.ReactNode)> | (optional) Visual content in the list item. |
disabled | boolean | (optional) Disables the list item from selection. |
groupIndex | number | (optional) What group index in the groups property this item belongs to. |
selectedKey | string number | (optional) If set, can be used instead of array index by the value prop. |
selectedValue | string React.ReactNode | (optional) Replaces the standard value output for selected item. Only used in some implementations (Dropdown, Autocomplete). |
suffixValue | string React.ReactNode | (optional) Content placed to the right in the list item. |
data as an object#
A simpler alternative, but with less options
// Each entry can contain the same type of value as the array's `content` propertyconst data = {first: "Item 1",,second: <span>Item 2</span>,last: ["Item 3", "Line 2", <span>Line 3</span>],}const onChange = ({ data, value }) => {console.log(data)// returns a generated object representing the item:// {// selectedKey: 'first',// value: 'first',// content: 'Item 1',// type: 'object'// }console.log(value) // returns the key ("first", "second", or "last"), instead of an index}
data types overview#
The following is an overview of all the types that the data property accepts. (These are not actual names of actual types in the library.)
// The visual content that is shown in one DrawerList item.// An array can be used to define multiple lines.type CONTENT = string | React.ReactNode | (string | React.ReactNode)[]// An array itemtype ARRAY_OBJECT = {content: CONTENTdisabled?: booleanselectedKey?: string | numberselectedValue?: string | React.ReactNodesuffixValue?: string | React.ReactNodestyle?: React.CSSProperties}// `data` as an array. A list of "ARRAY_OBJECT" types is preferred,// but the "CONTENT" type can be useful for simple lists.type ARRAY = (CONTENT | ARRAY_OBJECT)[]// `data` as an object. Can only contain the "CONTENT" type.// Each `key` behaves like the "ARRAY_OBJECT"'s `selectedKey`.type RECORD = Record<string, CONTENT>// An object or array that represents the entire DrawerList list.type DATA = ARRAY | RECORD// The final type of the `data` property:let data: DATA | () => DATA
JSON string#
There is technically support for sending in a JSON string of the data to the data property. But this is an old functionality that we do not really support anymore.
Translations#
More info about translations can be found in the general localization and Eufemia Forms localization docs.
| Key | nb-NO | en-GB | sv-SE | da-DK |
|---|---|---|---|---|
Autocomplete.title | Skriv og velg | Type and select | Skriv och välj | Skriv og vælg |
Autocomplete.submitButtonTitle | Vis alternativer | Show options | Visa alternativ | Vis muligheder |
Autocomplete.noOptions | Ingen alternativer | No options | Inga alternativ | Ingen muligheder |
Autocomplete.showAll | Vis alt | Show everything | Visa allt | Vis alt |
Autocomplete.showOptionsSr | Bla gjennom alternativer, lukk med esc knappen | Browse options, close with esc button | Bläddra genom alternativ, stäng med esc-knappen | Gennemse muligheder, luk med esc-knappen |
Autocomplete.ariaLiveOptions | %s alternativer | %s options | %s alternativ | %s muligheder |
Autocomplete.selectedSr | Valgt: | Selected: | Vald: | Valgt: |
Autocomplete.indicatorLabel | Henter data ... | Getting data ... | Hämtar data ... | Henter data ... |
DrawerList.defaultGroupSR | Standardvalg | Default options | Standardval | Standardvalg |
DrawerList.missingGroup | Gruppe | Group | Grupp | Gruppe |
DrawerList.noGroupSR | Andre valg | Other options | Andra val | Andre valg |