Skip to Content
🎉 Coral x Panda has been released 🎉 Read the Migration Guide

Dropdown

Available since version 23.28.0

A contextual menu or content area that appears when a user interacts with a specific element, such as a button.

Basic usage

import { Dropdown, DropdownTrigger, DropdownContent } from "@krakentech/coral"; <Dropdown> <DropdownTrigger asChild> <Button size="small" color="secondary" variant="outlined"> Menu </Button> </DropdownTrigger> <DropdownContent>Content</DropdownContent> </Dropdown>

Aria labelled by

NameDescriptionDefault
ariaLabelledByThe id of the element that describes the Dropdown. This should be an id of a child element. string""
<Dropdown ariaLabelledBy="dropdown-title"> <DropdownTrigger asChild> <Button size="small" color="secondary" variant="outlined"> Menu </Button> </DropdownTrigger> <DropdownContent> <Typography id="dropdown-title">Dropdown Title</Typography> </DropdownContent> </Dropdown>

Placement

NameDescriptionDefault
placementThe placement of the dropdown relative to the trigger. bottom, bottom-end, bottom-start, left, left-end, left-start, right, right-end, right-start, top, top-end, top-startbottom-start
<Dropdown placement="top"> <DropdownTrigger asChild> <Button size="small" color="secondary" variant="outlined"> Menu </Button> </DropdownTrigger> <DropdownContent>Content</DropdownContent> </Dropdown>

Note: This component uses Floating UI to calculate the position of the dropdown content — if there is not enough space in the viewport, it will automatically adjust the position to fit.

Offset

NameDescriptionDefault
offsetThe distance in pixels between the trigger and the dropdown. number12
<Dropdown offset={40}> <DropdownTrigger asChild> <Button size="small" color="secondary" variant="outlined"> Menu </Button> </DropdownTrigger> <DropdownContent>Content</DropdownContent> </Dropdown>

useCoralDropdown()

The Dropdown has its own context made available to the consumer via the useCoralDropdown hook. This hook provides the following properties:

NameDescription
openA boolean value indicating whether the Dropdown is open or not. boolean
openDropdownA function to set the Dropdown open. () => void
closeDropdownA function to set the Dropdown closed () => void
const { open, openDropdown, closeDropdown } = useCoralDropdown();

Example usage:

import { Dropdown, useCoralDropdown } from '@krakentech/coral'; const CustomTrigger = () => { const { open } = useCoralDropdown(); return ( <DropdownTrigger asChild> <Button color="secondary" variant="outlined" endIcon={ open ? ( <IconChevronUp size={16} /> ) : ( <IconChevronDown size={16} /> ) } > Menu </Button> </DropdownTrigger> ); }; const CustomContent = () => { const { closeDropdown } = useCoralDropdown(); return ( <DropdownContent> <Button size="small" color="secondary" variant="outlined" onClick={closeDropdown} > Close dropdown </Button> </DropdownContent> ); }; <Dropdown> <CustomTrigger /> <CustomContent /> </Dropdown>;

Full API

NameDescriptionDefault
ariaLabelledByThe id of the element that describes the Dropdown. This should be an id of a child element. string
placementThe placement of the dropdown relative to the trigger. bottom, bottom-end, bottom-start, left, left-end, left-start, right, right-end, right-start, top, top-end, top-startbottom-start
offsetThe distance in pixels between the trigger and the dropdown. number12
disableEscapeKeyDownOptionally disable the Escape keyboard handler booleanfalse
NameDescriptionDefault
asChildPass the functionality of the trigger down to the given child element booleanfalse
NameDescriptionDefault
paddingThe padding around the content of the dropdown. The same padding settings as our Card component. none, xsmall, small, medium, largemedium
themeThe theme of the Card wrapping the DropdownContent children. dark, mid, midLight, light, tertiaryLightdark
borderlessWhether the Card should be borderless. booleantrue
Last updated on