API

The parts of repousse and the props they take.

Anatomy#

Import Repousse and put the parts together.

import { Repousse } from "repousse/react";

<Repousse.Root>
	<Repousse.Trigger />
	<Repousse.Overlay />
	<Repousse.Menu>
		<Repousse.Item />
	</Repousse.Menu>
</Repousse.Root>;

Every part that renders an element takes that element's usual props and a ref.

Components#

Root#

Holds the state. It renders nothing of its own.

PropTypeDefault
onOpenChange(open: boolean) => void-
onClosed() => void-
containerElement | nulldocument.body

onOpenChange is called when the menu starts opening and when it starts closing. onClosed is called once it has finished closing.

Trigger#

The element you press. Renders a div with a button role, and takes div props.

PropTypeDefault
asChildbooleanfalse
clone(trigger: HTMLElement) => HTMLElement-

asChild puts the behaviour on your own element. clone builds the lifted copy yourself, for content a plain copy can't reproduce.

Overlay#

The layer behind the lifted copy, rendered while the menu is up. Takes div props. It's optional: without it, outside taps still dismiss the menu but nothing is painted.

The list of items, rendered while the menu is up. Takes div props.

PropTypeDefault
align"start" | "end""start"

align sets which edge of the trigger the menu lines up with. See Placement.

Item#

An option in the menu. Renders a button, and takes button props.

PropTypeDefault
onSelect() => void-
disabledbooleanfalse
asChildbooleanfalse

onSelect runs however the item is picked, by drag, tap or keyboard. With asChild, a link still navigates.

<Repousse.Item asChild>
	<a href="/thread">Open thread</a>
</Repousse.Item>

Data attributes#

SelectorWhat it is
[data-repousse-overlay]The overlay, including the one you don't render
[data-repousse-lifted]The lifted copy of the trigger
[data-highlighted]The item under a drag

Good to know#