Renders a widget based on the WAI-ARIA composite
role, which provides a single tab stop on the page and arrow key navigation
through the focusable descendants.
constHover=()=><Composite>(<><Composite.Hoverrender={<Composite.Item/>}> Hover item one
</Composite.Hover><Composite.Hoverrender={<Composite.Item/>}> Hover item two
</Composite.Hover><Composite.Hoverrender={<Composite.Item/>}> Hover item three
</Composite.Hover></>)</Composite>;
constWithSlotFill=()=><Composite>(<><Composite.Item>Item one (direct child)</Composite.Item><Slot/><Composite.Item>Item four (direct child)</Composite.Item></>)</Composite>;
With Tooltips
Combining the Tooltip and Composite component has a few caveats. And while there are a few ways to compose these two components, our recommendation is to render Composite.Item as a child of Tooltip. jsx // 🔴 Does not work </Tooltip>
constDefault=()=>{const[isOpen,setIsOpen]=useState(false);consthandleConfirm:typeofonConfirm=(confirmArgs)=>{onConfirm(confirmArgs);setIsOpen(false);};consthandleCancel:typeofonCancel=(cancelArgs)=>{onCancel?.(cancelArgs);setIsOpen(false);};return(<><Button__next40pxDefaultSizevariant="primary"onClick={()=>setIsOpen(true)}>Open ConfirmDialog
</Button><ConfirmDialogisOpen={isOpen}onConfirm={handleConfirm}onCancel={handleCancel}> Would you like to privately publish the post now?
</ConfirmDialog></>);};
When the role prop is either "menuitemcheckbox" or "menuitemradio", the isSelected prop should be used so screen readers can tell which item is currently selected.
Hide the label visually, while keeping available to assistive technology.
describedBy
string
Description for the select trigger button used by assistive technology.
If no value is passed, the text “Currently selected: selectedItem.name”
will be used fully translated.
label
string
Yes
Label for the control.
onChange
( newValue: CustomSelectChangeObject< NoInfer< T > > ) => void
Function called with the control’s internal state changes. The selectedItem
property contains the next selected item.
options
ReadonlyArray< T >
Yes
The list of options that can be chosen from.
size
'default' | 'small' | '__unstable-large'
The size of the control.
@default ‘default’
value
NoInfer< T >
Can be used to externally control the value of the control.
showSelectedHint
boolean
Show the hint of the selected item in the trigger button.
@default false
__next40pxDefaultSize
boolean
Start opting into the larger default height that will become the default size in a future version.
Disabled is a component which disables descendant tabbable elements and
prevents pointer interaction.
Note: this component may not behave as expected in browsers that don’t
support the inert HTML attribute. We recommend adding the official WICG
polyfill when using this component in your project.
If you want to target the dropdown menu for styling purposes,
you need to provide a contentClassName because it’s not being rendered
as a child of the container node.
expandOnMobile
boolean
Opt-in prop to show popovers fullscreen on mobile.
@default false
focusOnMount
useFocusOnMount.Mode
Determines focus behavior when the dialog mounts.
"firstElement" focuses the first tabbable element within.
"firstInputElement" focuses the first value control within.
true focuses the element itself.
false does nothing and should not be used unless an accessible
substitute behavior is implemented.
@default ‘firstElement’
headerTitle
string
Set this to customize the text that is shown in the dropdown’s header
when it is fullscreen on mobile.
onClose
() => void
A callback invoked when the popover should be closed.
onToggle
( willOpen: boolean ) => void
A callback invoked when the state of the dropdown changes
from open to closed and vice versa.
Properties of popoverProps object will be passed as props
to the Popover component.
Use this object to access properties/features
of the Popover component that are not already exposed
in the Dropdown component,
e.g.: the ability to have the popover without an arrow.
renderContent
( props: CallbackProps ) => ReactNode
Yes
A callback invoked to render the content of the dropdown menu.
Its first argument is the same as the renderToggle prop.
renderToggle
( props: CallbackProps ) => ReactNode
Yes
A callback invoked to render the Dropdown Toggle Button.
The first argument of the callback is an object
containing the following properties:
isOpen: whether the dropdown menu is opened or not
onToggle: A function switching the dropdown menu’s state
from open to closed and vice versa
onClose: A function that closes the menu if invoked
style
CSSProperties
The style of the global container.
open
boolean
The controlled open state of the dropdown.
Must be used in conjunction with onToggle.
defaultOpen
boolean
The open state of the dropdown when initially rendered.
Use when you do not need to control its open state. It will be overridden
by the open prop if it is specified on the component’s first render.
Examples
Default
constDefault=()=><DropdownonClose={fn()}onToggle={fn()}renderToggle={({isOpen,onToggle})=>(<Button__next40pxDefaultSizeonClick={onToggle}aria-expanded={isOpen}variant="primary"> Open dropdown
</Button>)}renderContent={()=><div>This is the dropdown content.</div>}/>;
With More Padding
To apply more padding to the dropdown content, use the provided <DropdownContentWrapper> convenience wrapper. A paddingSize of "medium" is suitable for relatively larger dropdowns (default is "small").
The <DropdownContentWrapper> convenience wrapper can also be used to remove padding entirely, with a paddingSize of "none". This can also serve as a clean foundation to add arbitrary paddings, for example when child components already have padding on their own.