Usage

import { Dropdown } from '@loomhq/lens'

<Dropdown
  triggerCallback={buttonProps => <div tabIndex="0" {...buttonProps}>Simple trigger</div>}
  options={[
    {
      title: 'Share',
      icon: <SvgShare />,
      onClick: () => (),
      disabled: false,
    },
  ]}
/>

ARIA Menu Name

Screen readers should accurately 'read' the text contents of the custom node you return from the callback you pass to trigger as the label for the Dropdown element. However, you can explicitly pass a label string to ariaMenuName to explicitly label the element in case screen readers are not behaving as expected.

Trigger

triggerCallback

A callback function that returns a custom node. The Dropdown component will pass the necessary ARIA attributes to allow screen readers to properly 'read' the custom node returned by your callback.

Providing this prop will override any custom node passed to trigger.

trigger (deprecated - use triggerCallback instead)

Trigger can be any custom node. If the trigger is not a button make sure to add a tabindex attribute to it.

Note on deprecation: This approach is not a11y compliant, as screen readers cannot properly 'read' the dropdown options. Using a screen reader, you can test the buttons below. Only the first should have its menu items read.

Menu can be positoned on the left or right side relative to the trigger.

With icons

See the Icon set.

With divider

Min and max width

Max height

Container

Specify where it's going to be rendered in the DOM, this is especially useful when working with Shadow DOM.

<Dropdown
  container={() => document.querySelector("#renderContainer")}
  triggerCallback={buttonProps => <Button {...buttonProps}>Trigger</Button>}
  options={[
    { title: 'A' },
    { title: 'B' },
    { title: 'C' }
  ]}
/>

For dropdowns with many options that make it difficult to find the intended value, a search input can be added. By default, the option values are filtered on the inputted value using a loose includes pattern.

With string options

With ReactElement options

For options that implement a ReactElement as the title of the options property, the element properties must be joined with React.PropsWithChildren or have the children property. Furthermore, the searchable value of the element must be included as a child of the element to ensure its value can be parsed.

onOuterClick callback

onOpenChange callback

Callback that provides the isOpen value when dropdown opens or closes

Props

name
type
default
menuPosition
| 'left' | 'right' | 'topRight' | 'topLeft' | 'leftSide' | 'rightSide'
'left'
menuZIndex
number
1100
menuMinWidth
number | string
24
menuMaxWidth
number | string
48
triggerOffset
number
0
ariaMenuName
string
options
OptionsObject[]
isOpen
boolean
menuMaxHeight
number | string
container
HTMLElement | (() => HTMLElement) | string
onOuterClick
() => void
onOpenChange
(isOpen: boolean) => void
search
{ searchPlaceholder: string; searchType?: 'contains' | 'startsWith'; }
role
React.AriaRole
menuItemRole
React.AriaRole