Skip to content

Events#

TypeDescription
onChangefunction(optional) Will be called on state changes made by the user. Returns an object with the new selected data item { data, event, attributes, value }.
onSelectfunction(optional) Will be called once the user focuses or selects an item by a click or keyboard navigation. Returns an object with the new selected data item { data, event, attributes, value, activeItem }. The activeItem property is the currently selected item by keyboard navigation.
onOpenfunction(optional) Will be called once the user presses the dropdown. Returns the data item { data, attributes }.
onClosefunction(optional) Will be called once the user presses the dropdown again, or clicks somewhere else. Returns the data item { data, attributes }.
onOpenFocusfunction(optional) Will be called when focus is set on an item inside the opened drawer list. Returns { element } with the focused DOM element.
onCloseFocusfunction(optional) Will be called when focus is moved back to the trigger button after the drawer list closes. Returns { element } with the focused DOM element.
onKeyDown(event: React.KeyboardEvent<HTMLButtonElement>) => void(optional) Will be called when a key is pressed while the trigger button has focus. Call event.preventDefault() to skip the built-in key handling, such as opening the list.
onKeyUp(event: React.KeyboardEvent<HTMLButtonElement>) => void(optional) Will be called when a key is released while the trigger button has focus.

The onChange vs onSelect difference#

The difference between onChange and onSelect is:

  • onChange will be called when the state changes, either with a click or space/enter keypress confirmation.
  • onSelect differs most when the user is navigating by keyboard. Once the user is pressing e.g. the arrow keys, the selection is changing, but not the state.
Suggest an edit
Eufemia · /web/components/dropdown/events/ · Version [LOCAL BUILD]