suiss/ui · Component
Drawer
A panel that slides in from an edge of the screen and can be dismissed with a swipe.
Drawer is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Drawer wraps the Base UI Drawer. The Drawer root manages the open state and the swipe direction, and DrawerTrigger opens it. DrawerContent renders the panel in a portal, over a dimmed DrawerOverlay when modal, with an optional swipe handle and close button. Inside it, DrawerHeader holds the DrawerTitle and DrawerDescription, and DrawerFooter holds the actions. DrawerClose closes the drawer from any element.
The drawer opens from the bottom by default and can also open from the top, left or right. It supports snap points, a floating style inset from the screen edges, a non-modal mode and a page behind it that scales down. Use a drawer for touch-friendly, swipeable panels; for a centered window, use a dialog.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Usage
Composition
Use the following composition to build a Drawer:
Examples
Directions
Set swipeDirection to down, up, left or right to choose the edge the drawer opens from and the direction it is swiped to close.
With close button
Set showCloseButton on DrawerContent to add an icon close button in the top corner.
With close label
Set closeLabel on DrawerContent to replace the close button's icon with text.
Floating
Set floating to inset the drawer from the screen edges and round all of its corners.
With snap points
Pass snapPoints, such as [0.5, 1], to let people drag the drawer between heights. This one opens at half height and expands when dragged up.
Non modal
Set modal={false} to keep the rest of the page interactive. No overlay is rendered in that case.
Sheet with detents
An event sheet with snap points that scales the page behind it. Place DrawerIndentBackground and DrawerIndent inside DrawerProvider and put the page content in DrawerIndent.
Accessibility
- The panel has the
dialogrole.DrawerTitleprovides its accessible name andDrawerDescriptionits accessible description. - Opening the drawer moves focus inside it. Escape closes it and returns focus to the trigger.
- A non-modal drawer does not set
aria-modal. - The swipe handle is hidden from assistive technology, so always provide another way to close the drawer, such as a
DrawerClosebutton. - The icon-only close button has a visually hidden
Closelabel.
API Reference
DrawerProvider
Coordinates drawers with DrawerIndent so the page can react when a drawer opens.
Also accepts the props of DrawerPrimitive.Provider.Props.
Place DrawerIndentBackground and DrawerIndent inside it and put the page content in DrawerIndent.
DrawerIndentBackground
The dark layer shown behind the page when it scales down.
Also accepts the props of DrawerPrimitive.IndentBackground.Props.
DrawerIndent
Wraps the page content and scales it down while a bottom drawer is open.
Also accepts the props of DrawerPrimitive.Indent.Props.
The page is scaled while a non-floating drawer that opens from the bottom is open, and, with snap points, only at the last snap point. It gets data-raised while the page is scaled. Animations are disabled when reduced motion is preferred.
Drawer
The root that manages the open state, swipe direction and snap points.
| Prop | Type | Default |
|---|---|---|
floating | boolean | false |
showSwipeHandle | boolean | false |
Also accepts the props of DrawerPrimitive.Root.Props.
The drawer is uncontrolled by default; set defaultOpen to start open, or control it with open and onOpenChange. With snapPoints it opens at the first snap point unless you set defaultSnapPoint, or control it with snapPoint and onSnapPointChange. showSwipeHandle shows a grab bar on the edge of the panel that faces the screen center. Nested drawers stack, with the drawer behind scaled down slightly.
DrawerTrigger
The button that opens the drawer.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Also accepts the props of DrawerPrimitive.Trigger.Props.
Render the trigger as another component, such as a Button, with the render prop.
Set asChild to render your own Button as the trigger instead of a button.
DrawerPortal
Renders its children into a portal outside the current DOM hierarchy.
Also accepts the props of DrawerPrimitive.Portal.Props.
DrawerClose
A button that closes the drawer.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Also accepts the props of DrawerPrimitive.Close.Props.
Render the close button as another component, such as a Button, with the render prop.
Set asChild to render your own Button as the close button instead of a button.
DrawerOverlay
The dimmed layer behind a modal drawer, which fades as the drawer is swiped away.
Also accepts the props of DrawerPrimitive.Backdrop.Props.
DrawerSwipeHandle
The grab bar people drag to move or dismiss the drawer.
Also accepts the props of React.ComponentProps<"div">.
DrawerContent
The drawer panel, rendered in a portal with an optional overlay, swipe handle and close button.
| Prop | Type | Default |
|---|---|---|
showCloseButton | boolean | false |
closeLabel | string | - |
Also accepts the props of DrawerPrimitive.Popup.Props.
The panel sets data-swipe-direction, data-swipe-axis, and, when applicable, data-floating and data-snap-points. A drawer at its last snap point gets data-expanded. Side drawers are 75% wide, and 24rem wide from the sm breakpoint. Top and bottom drawers are limited to the viewport height minus 6rem.
DrawerHeader
Groups the title and description.
Also accepts the props of React.ComponentProps<"div">.
DrawerFooter
Holds the drawer's actions at the bottom of the panel.
Also accepts the props of React.ComponentProps<"div">.
DrawerTitle
The drawer's title, which also names it for assistive technology.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Also accepts the props of DrawerPrimitive.Title.Props.
DrawerDescription
Supporting text that describes the drawer for assistive technology.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Also accepts the props of DrawerPrimitive.Description.Props.
Each part sets a data-slot, such as drawer-content or drawer-swipe-handle, for styling.
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Drawer presents content in a panel attached to an edge of the screen. It slides in from the bottom by default, or from the top, left or right with swipeDirection, and the user can drag it closed in that direction. The content renders through a portal (inside a full-window overlay on iOS) and respects the safe-area insets.
Installation
- Install the following dependencies:
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/drawer.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/drawer.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/drawer.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Examples
Default
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Snap points
A drawer that rests at 40% and full height.
snapPoints accepts fractions of the screen such as [0.4, 1]; control the current one with snapPoint and onSnapPointChange.
Web preview
Floating
Set floating to inset the panel from the screen edges with all corners rounded.
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Sides
Set swipeDirection to open drawers from the top, bottom, left and right.
Web preview
The React Native tab shows 2 more examples.
The React Native tab shows 1 more example.
Accessibility
- The popup has the
dialogrole and is labelled by the title. - The swipe handle and decorative edge fill are hidden from screen readers.
- The icon close button is labelled "Close".
API Reference
DrawerProvider
Tracks open drawers for the indent effect.
Also accepts the props of DrawerPrimitive.ProviderProps.
Wrap your app in it and render DrawerIndentBackground behind a DrawerIndent that holds the screen, to scale the page back behind an open bottom drawer.
DrawerIndentBackground
Background shown behind the scaled screen.
Also accepts the props of React.ComponentProps<typeof DrawerPrimitive.IndentBackground>.
DrawerIndent
Screen wrapper that scales back while a bottom drawer is open.
Also accepts the props of React.ComponentProps<typeof DrawerPrimitive.Indent>.
Drawer
Root that holds the open state, direction and snap points.
| Prop | Type | Default |
|---|---|---|
floating | boolean | false |
showSwipeHandle | boolean | false |
Also accepts the props of DrawerPrimitive.RootProps.
showSwipeHandle shows a grab handle. With modal={false} there is no scrim. A docked drawer extends its background past the screen edge so drag overshoot shows no gap, and animations respect the system Reduce Motion setting.
DrawerOverlay
Dimmed scrim behind a modal drawer.
Also accepts the props of React.ComponentProps<typeof DrawerPrimitive.Backdrop>.
DrawerSwipeHandle
Grab handle on the dragging edge.
Also accepts the props of ViewProps.
DrawerContent
Sliding panel with optional handle and close button.
| Prop | Type | Default |
|---|---|---|
portalHost | string | - |
showCloseButton | boolean | false |
closeLabel | string | - |
Also accepts the props of React.ComponentProps<typeof DrawerPrimitive.Popup>.
Set showCloseButton for a corner close button, and closeLabel to show text instead of the icon. portalHost names the portal host to render into. Padding follows the safe-area insets. Use DrawerClose to close the drawer from a button.
DrawerHeader
Area for the title and description.
Also accepts the props of ViewProps.
DrawerFooter
Area for actions at the end of the panel.
Also accepts the props of ViewProps.
DrawerTitle
Drawer heading, centered for top and bottom drawers.
Also accepts the props of React.ComponentProps<typeof DrawerPrimitive.Title>.
DrawerDescription
Supporting text.
Also accepts the props of React.ComponentProps<typeof DrawerPrimitive.Description>.
.drawer
| Parameter | Type | Default |
|---|---|---|
isPresented | Binding<Bool> | - |
detents | Set<PresentationDetent>? | nil |
selection | Binding<PresentationDetent>? | nil |
onDismiss | (() -> Void)? | nil |
content | () -> Content | - |
DrawerContent
Sliding panel with optional handle and close button.
| Parameter | Type | Default |
|---|---|---|
showCloseButton | Bool | false |
closeLabel | LocalizedStringKey? | nil |
content | () -> Content | - |
DrawerHeader
Area for the title and description.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
DrawerFooter
Area for actions at the end of the panel.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
Drawer
Root that holds the open state, direction and snap points.
| Parameter | Type | Default |
|---|---|---|
open | Boolean | - |
onOpenChange | (Boolean) -> Unit | - |
modifier | Modifier | Modifier |
snapPoints | List<Float> | emptyList() |
onSnapPointChange | (Float) -> Unit | {} |
floating | Boolean | false |
showSwipeHandle | Boolean | false |
showCloseButton | Boolean | false |
closeLabel | String? | null |
content | @Composable ColumnScope.() -> Unit | - |
DrawerHeader
Area for the title and description.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable ColumnScope.() -> Unit | - |
DrawerFooter
Area for actions at the end of the panel.
Receiver: ColumnScope.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable ColumnScope.() -> Unit | - |
DrawerTitle
Drawer heading, centered for top and bottom drawers.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
DrawerDescription
Supporting text.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |