Skip to main content

Drawer

A drawer panel that slides in from a screen edge, commonly used for details or forms that need more display space. Differences from Dialog: it hugs an edge, slides by direction, and the panel size applies to a single side (width or height).

Basic usage​

Four directions and custom sizes
import { useState } from 'react'
import { LhButton, LhDrawer } from '@lh-ui/react'

export default function Demo() {
const [open, setOpen] = useState(false)
return (
<>
<LhButton onClick={() => setOpen(true)}>Open drawer</LhButton>
<LhDrawer title="Drawer title" open={open} onClose={() => setOpen(false)}>
Drawer content
</LhDrawer>
</>
)
}

Drawer Props​

PropDescriptionTypeOptionsDefault
childrenBody contentReactNode——
openWhether to show (controlled)boolean—false
titleTitleReactNode——
directionSlide-in direction'right' | 'left' | 'top' | 'bottom'—'right'
sizePanel size (number → px; string supports percentages)string | number—'30%'
showCloseWhether to show the close buttonboolean—true
maskClosableWhether clicking the modal closes the drawerboolean—false
closeOnEscWhether Esc closes the drawerboolean—true
lockScrollWhether to lock body scroll (also traps focus when locked)boolean—true
beforeCloseIntercept before closing; closing only proceeds when done is called(done: () => void) => void——
zIndexz-index (falls back to the global increasing system when omitted)number——
headerHeader content (overrides the default title bar)ReactNode——
footerFooter content (button area)ReactNode——
themeVarsComponent-level theme variablesRecord<string, string>——
sxShorthand layout props (applied to the panel)SxProps——

Drawer events​

EventDescriptionCallback signatureVue equivalent
onCloseClose request (modal / Esc / close button; emitted after beforeClose interception)() => voidupdate:modelValue / close
onOpenEmitted when opening (after DOM mount, before the enter animation)() => voidopen
onOpenedOpen animation ended() => voidopened
onCloseStartThe close request was accepted and the leave animation has started() => void—
onClosedAfter the close animation ends and the DOM is unmounted() => voidclosed

ref​

forwardRef<LhDrawerInstance>. LhDrawerInstance exposes close() (goes through beforeClose interception) and isOpen.

Modal is not clickable by default

maskClosable defaults to false (core's canDrawerClose rejects modal clicks by default) to avoid accidental triggers; plus's closeOnClickModal defaults to true, so declare it explicitly when migrating.

Focus trap

Focus is trapped only when lockScroll is on (shouldDrawerTrapFocus): a drawer is often a lightweight panel, and when scroll is not locked the Tab order of the form behind it is preserved. Focus is returned on close.

Size direction

A numeric size is normalized to px; for the left / right directions it applies to the panel width, and for the top / bottom directions it applies to the height.

Styles​

import '@lh-ui/react/style/drawer'