Tonic UI
Getting StartedColor ModeColor StyleVersionsContributing
THEME
BordersBreakpointsColorsOutlinesPositionsSpacingSizesShadowsTypography
BUILDING BLOCKS
BoxControlBox
UTILITIES

Drawer

A drawer dialog is a window overlaid on either the primary window or another dialog window. Contents behind a drawer dialog are inert meaning that users cannot interact with content behind the dialog.

Import

  • Drawer: A Provider component that provides the context to the components it wraps.
  • DrawerOverlay: The overlay of the drawer.
  • DrawerContent: The content of the drawer.
  • DrawerHeader: The header of the drawer.
  • DrawerBody: The body of the drawer.
  • DrawerFooter: The footer of the drawer.

Usage

Click the button below to toggle a drawer. The drawer will show up on either side of the screen.

EDITABLE EXAMPLE

Placements

Use the placement prop to if you want to change the placement of the drawer. The value can be one of right (default) or left.

EDITABLE EXAMPLE

Sizes

Use the size prop to change the size of the Drawer. You can set the value to auto, sm, md, lg, or full.

EDITABLE EXAMPLE

Transitions

The drawer doesn't come with transitions by default. You can use the Transition components to provide simple transitions.

When using transitions, you have to set isOpen to true, or the transition will not take effect when closing the drawer.

Adding slide transition

EDITABLE EXAMPLE

Props

Drawer

NameTypeDefaultDescription
ensureFocusbooleanfalseIf true, it will always bring the focus back to the Drawer descendants, which does not allow the focus to escape while open.
autoFocusbooleanfalseIf true and ensureFocus is true and initialFocusRef is not set, it will automatically set focus on the first focusable element.
backdropbooleanfalseIf true, it will wrap components with a backdrop to provide a click area for dismissing when clicking outside the drawer.
finalFocusRefReact.refThe ref of element to receive focus when the drawer closes.
initialFocusRefReact.refThe ref of the element to receive focus when the drawer opens.
isOpenbooleanfalseIf true, the drawer is shown.
isClosablebooleanfalseIf true, a close button will appear on the right side.
closeOnEscbooleanfalseIf true, close the drawer when the esc key is pressed.
closeOnOutsideClickbooleanfalseIf true, close the drawer when click outside of the drawer. Note that this value will not have any effect when backdrop is set to true.
onClosefunctionCallback fired when the drawer closes.
placementstring'right'The placement of the drawer. One of: 'left', 'right'
sizestring'auto'The size of the drawer. One of: 'auto', 'sm', 'md', 'lg', 'full'

DrawerOverlay

DrawerContent

DrawerHeader

DrawerBody

DrawerFooter