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' }
  ]}
/>

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