Skip to main content

Dropdown: React

An overlay list of options, which are hidden by default but can be shown by interacting with a button or other component.

Installation

Before you can start using the @mediahuis/chameleon-react component, you’ll need to install it, for more information check: Getting started for developers.

With that done, you’re now ready to implement the component in your application.

import { Dropdown, DropdownItem } from '@mediahuis/chameleon-react';

export default function Example() {
const anchorRef = React.useRef(null);

return (
<>
<Button ref={anchorRef}>Click here to open</Button>
<Dropdown anchorRef={anchorRef}>
<DropdownItem>
<Dropdown/>
</>
);
}
PropertyTypeDefaultRequiredDescription
anchorRefRefObject-YesReference to the element which you want to use for positioning of the dropdown.
childrenReactNode-NoThe children of the Dropdown component.
defaultOpenBooleanfalseNoDetermines the visibility state of the dropdown by default.
idString-YesSets the native HTML id attribute. It will also affect the describedby-id for accessibility reasons.
placementPlacement'bottom-start'NoDetermines where the Dropdown is positioned towards the target element.
PropertyTypeDefaultRequiredDescription
clickableBooleantrueNoDetermines if clickable styles are added when set to true.
iconRightElementType-NoControls the `as` prop of the Icon on the right side.
titleReactNode-YesThe text inside the DropdownItem.