Sheet
A panel that slides in from an edge of the page.
Sheets open from the right unless you set side to left, top or bottom. Drag one back
toward its edge, press outside or press Escape to close it. The body scrolls when there’s more
than fits.
Dependencies
What it's built from and what's built from it in Mocha, read from the imports in its source.
| Uses | Scroll AreaprimitiveTextprimitive |
|---|---|
| Used by | Nothing yet. |
| Packages | @ui-sdk/core@0.1.0-beta.20@ui-sdk/react@0.1.0-beta.20 |
Installation
Set the project up for Mocha once first, as Getting started shows. Then add it with the CLI, or by hand.
With the CLI
Manually
Install its packages:
Add the components it uses first, listed under Dependencies.
Then copy the source:
API reference
Generated from Mocha's types. Props marked ours are added here; the rest come from the ui-sdk part it wraps. Every part also accepts its element's native attributes.
Sheet
A panel that slides in from an edge of the page, the right one unless you set side. Drag it back to close.
- closeOnOutsidePress
Whether pressing outside the drawer, like on its backdrop, closes it.
Type boolean · Default true, or false while the drawer isn't modal
- container
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
Type Element | DocumentFragment | null
- controller
Opens, closes and moves the drawer from anywhere, and connects triggers and outlets outside it. Create one with
createDrawerController().Type DrawerController<any, any>
- debug
Logs every state change with its reason to the console, in development builds.
Type boolean
- defaultOpen
Whether the dialog starts open, when uncontrolled. Focus moves into it once it's on the page.
Type boolean · Default false
- defaultSnapPoint
The snap point it opens at, when uncontrolled. It opens there again each time.
Type SnapPoint · Default the first of `snapPoints`
- dismissible
Whether Escape, an outside press and Android's back gesture can close the dialog. Close parts, triggers and the controller always can. Pass
falsewhile a form has unsaved changes, and ask inonDismissAttempt.Type boolean · Default true
- driver
How it moves.
"pointer"follows touch, mouse and pen with a spring fitted to iOS."scroll-snap"uses the browser's own scrolling for bottom drawers."auto"picks scroll snap for a bottom drawer on a touch screen, unlessmodalAboveis set orexpandOnScrollis false, and the pointer driver otherwise.Type SheetDriverName · Default "auto"
- expandOnScroll
Whether dragging toward a larger snap point on scrollable content moves the drawer first, until it's at its largest.
Type boolean · Default true
- modal
true: the rest of the page is inert and doesn't scroll, focus is trapped, and an outside press only closes the drawer."trap-focus": traps focus and leaves the page usable.false: a drawer beside the page. SeemodalAboveto make it modal only above a snap point.Type boolean | "trap-focus" · Default true
- modalAbove
At or below this snap point the page stays usable and undimmed, like Maps: no inert page, no scroll lock, no
aria-modal, and presses beside the drawer reach the page. Above it,modalapplies. Changes once the drawer comes to rest.Type SnapPoint
- onDismissAttempt
Runs when a dismissal was refused because
dismissibleis false, including a swipe. The drawer resists and springs back. Ask "Discard changes?" here.Type (details: DrawerDismissAttemptDetails) => void
- onOpenChange
Runs when the drawer wants to open or close.
details.reasonsays why,"swipe"included,details.cancel()stops it, anddetails.returnValuecarries what closed it.Type (open: boolean, details: DialogOpenChangeDetails<DrawerOpenChangeReason>) => void
- onOpenChangeComplete
Runs once the dialog has finished opening or closing, after any animation.
Type (open: boolean) => void
- onPayloadChange
Runs when the payload the content shows changes: a trigger with another payload opens the drawer, or takes a non-modal drawer over while it's open, which fires no
onOpenChange, and so does a controller'sopen({ payload })on the open drawer.details.cancel()keeps the previous payload.Type (payload: unknown, details: ChangeDetails<DialogPayloadChangeReason>) => void
- onSnapPointChange
Runs when the drawer moves to another snap point.
details.reasonsays why: a swipe, the handle, the keyboard, a resize or the controller.Type (snapPoint: SnapPoint, details: ChangeDetails<DrawerSnapPointChangeReason>) => void
- open
Whether the dialog is open. Pass it to control the dialog.
Type boolean
- pendingAnnouncement
What screen readers hear once a Close part's action has been running for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.
Type string · Default "Loading"
- persistentElements
Elements that stay usable while the dialog makes the page inert, like a chat launcher or a password manager's button. Elements, CSS selectors, or a function that returns elements, read when the dialog opens. Presses on them never close it.
Type (string | Element)[] | (() => Element[])
- physics
Overrides the motion: spring, projection, rubber band and dim. Starts from
sheetPhysics.ios.Type Partial<SheetPhysics>
- preventEdgeSwipe
Whether presses on the drawer near the screen's left and right edges are kept from starting iOS Safari's back and forward swipe. Taps right at those edges then don't click. Read when the content mounts.
Type boolean · Default false
- side
The edge it comes from.
"start"and"end"follow the writing direction.Type Side · Default right
- snapPoint
The snap point it rests on. Pass it to control it.
Type SnapPoint | null
- snapPoints
Where the drawer can rest, from the edge it comes from: a fraction of the screen up to 1, pixels above 1,
"…px","…rem","…%", or"content"for its own size. None can be larger than the drawer, which you size with CSS.Type SnapPoint[] · Default ["content"]
- themeColor
Whether
<meta name="theme-color">dims with the backdrop, so Safari's toolbars darken too. Written where motion starts and ends, never per frame.Type boolean · Default false
SheetBackdrop
Dims the page behind the sheet. Its opacity follows the drag.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: DrawerBackdropState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: DrawerBackdropState) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<DrawerBackdropState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: DrawerBackdropState) => CSSProperties)
SheetBody
The sheet's body, which scrolls when there's more than fits.
Takes the props of a native div.
SheetContent
The sheet itself. Give it a SheetTitle.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: DrawerContentState<unknown>) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: DrawerContentState<unknown>) => string)
- container
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
Type Element | DocumentFragment | null
- finalFocus
Where focus goes when the dialog closes while focus is inside it.
Type PopupFocusTarget · Default "trigger"
- initialFocus
Where focus goes when the dialog opens. Opening with touch focuses the dialog itself, so no on-screen keyboard appears, unless this is set to something other than
"auto".Type DialogInitialFocus · Default "auto"
- keepMounted
Whether the dialog stays in the page, hidden, while closed. Its content keeps its state between opens.
Type boolean · Default false
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<DrawerContentState<unknown>>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: DrawerContentState<unknown>) => CSSProperties)
SheetDescription
Describes the sheet.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: {}) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: {}) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<{}>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: {}) => CSSProperties)
SheetFooter
Actions at the bottom of the sheet.
Takes the props of a native div.
SheetHeader
The title, description and anything else at the top of the sheet.
Takes the props of a native div.
SheetTitle
Names the sheet.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: {}) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: {}) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<{}>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: {}) => CSSProperties)
DrawerTrigger
The button that opens the drawer. A trigger outside the drawer, like one per table row, connects through controller.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: DialogTriggerState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: DialogTriggerState) => string)
- controller
Connects a trigger outside the drawer, like one per table row, to the drawer with this controller.
Type DrawerController<any, any>
- disabled
Stops presses. The button is natively disabled, so it leaves the tab order and its form doesn't submit through it, unless
focusableWhenDisabledis set.Type boolean · Default false
- focusableWhenDisabled
Keeps a disabled trigger in the tab order with
aria-disabledinstead of the native attribute, so it can host a tooltip that says why. Presses still do nothing.Type boolean · Default false
- payload
Data for the content to render when this trigger opens the dialog, like the row it belongs to.
Type unknown
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<DialogTriggerState>
- shortcut
A keyboard shortcut that presses the trigger, like
"mod+k".modis Command on Apple platforms and Control elsewhere. Setsaria-keyshortcuts, and a Shortcut part inside shows it. A modal dialog pauses the page's shortcuts while it's open.Type string
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: DialogTriggerState) => CSSProperties)