ZUI

Search documentation

Find a page or a heading.

Sheet

A panel that slides over the screen from one of its edges.

Installation

bash

The CLI writes components/ui/sheet.tsx, lib/motion.ts and lib/overlay.ts, installs Direction, Button, Icon, Text and Utils, and adds @rn-primitives/dialog, @rn-primitives/portal, lucide-react-native, react-native-reanimated and react-native-worklets. The content draws in the app's PortalHost; see Add a portal host. Without one it draws nothing, and logs an error saying so while the app is in development.

Usage

tsx
tsx

API reference

Sheet

Takes every prop of React Native's View, plus open, defaultOpen and onOpenChange(open). Without open the Sheet holds its own state, starting from defaultOpen.

SheetTrigger and SheetClose

Take every prop of React Native's Pressable. SheetTrigger opens the Sheet and SheetClose closes it. Pass asChild to make a Button do it. Focus returns to the trigger when the Sheet closes.

SheetContent

Takes every prop of React Native's View, plus:

side attaches the panel to that edge: across the top or bottom at its content's height, or down the left or right at three quarters of the screen's width. The panel is a modal dialog named by its SheetTitle, over a dimmed overlay. Accessibility focus moves into it as it opens. A press on the overlay, the Android back button, the iOS escape gesture (a two-finger Z) and Escape on the web close it. It fades in while sliding 2.5rem in from its side over 200ms, and out the same way. When the system asks for reduced motion it appears and goes at once.

VoiceOver stays inside the sheet while it is open. TalkBack does once the app hides its screens from screen readers while an overlay is shown, as Add a portal host shows; the web hides the rest of the page itself.

The panel runs to the screen's edge, under the status bar or the home indicator. Pad it by the safe area's insets where it meets them, such as with useSafeAreaInsets from react-native-safe-area-context.

SheetHeader and SheetFooter

Take every prop of React Native's View. The footer is pushed to the end of the panel and stacks its children.

SheetTitle and SheetDescription

Take every prop of Text. The title is a heading.

Right to left

A left or right sheet stays on the side it names, as upstream's does, which places it with left-0 and right-0. A device the system lays out right to left draws left styles on the right, unless the app turned that off with I18nManager.swapLeftAndRightInRTL(false); there the sheet slides in from the side it is drawn on. That follows the system's direction, not a provider's, since a provider changes no layout on a device.

Differences from upstream

  • Upstream's render prop becomes asChild, as on every native item.
  • On iOS, VoiceOver does not read aria-labelledby, so the sheet is not announced by its title's name there. Focus moves into the content, where the title is the first thing read. Android and the web read the name.
  • The overlay fades over the sheet's 200ms rather than upstream's 150ms, as one animation drives both.
  • Upstream caps a side panel at max-w-sm from sm and blurs the screen behind the overlay. A phone is narrower than sm, and React Native has no backdrop blur.
  • Upstream's animation runs whatever the system's motion setting. The native one is skipped when the system asks for reduced motion.
  • portalHost is added, for an app that draws overlays into a PortalHost of its own.