Tiny/Drawer

Integration

Features & Props

One place to understand how tiny-drawer works, what the runtime lifecycle looks like, and which options or props are available in both the core and React packages.

How it works

The core package creates a drawer instance against a host container. Nothing touches the DOM until you create that instance on the client. From there, the drawer mounts its UI, manages open and close state, handles drag resizing or scroll-full expansion, and dispatches callbacks plus custom events from the original parent container.

The React package keeps that same behavior, but wraps it in a component and hook API. React still owns your state and children, while the wrapper creates and updates the underlying TinyDrawer instance inside effects.

1. Create

Choose the package, import its CSS, and create the drawer only on the client.

2. Configure

Set placement, size, drag limits, close behavior, parent mounting, scroll-full rules, and callbacks.

3. Control

Open or close it with instance methods, events, React state, refs, or the hook API.

Core package options

These options apply to new TinyDrawer(container, options) from the tiny-drawer package.

OptionTypeDefaultHow it works
position"top" | "right" | "bottom" | "left""bottom"Controls which edge the drawer attaches to.
sizestring | number"40%"Default open size for the drawer.
minSizestring | number"20%"Smallest size allowed during drag resize.
maxSizestring | number"90%"Largest size allowed during drag resize.
contentstring | HTMLElementundefinedAccepts HTML, text, selectors, or a real element.
parentContainerstring | HTMLElementundefinedMounts the drawer host inside a specific parent element.
themePrefixstringundefinedAdds prefixed theme classes such as acme-drawer.
backdropbooleantrueShows or hides the backdrop layer.
closeButtonbooleantrueRenders the close button inside the drawer.
closeOnBackdropbooleantrueCloses only when the backdrop itself is clicked.
outSideClickClosebooleanfalseCloses when the user clicks outside the mounted parent or container boundary.
closeOnEscapebooleantrueEnables keyboard escape to close.
draggablebooleantrueTurns on the resize handle and pointer-driven drag behavior.
onScrollFullboolean | { backDrop?: boolean; drawer?: boolean; scrollTarget?: HTMLElement | string | null }falseDisables drag and enables scroll-to-full behavior. Use an object in 1.2.0 to choose whether backdrop scroll, drawer scroll, or a custom scrollTarget can trigger fullscreen expansion.
fullScreenGapstring | number0Keeps space from the opposite edge while scroll-full mode is active.
animationbooleantrueDisables transitions when set to false.
appendToBodybooleantrueKeeps the drawer mounted on document.body with fixed positioning.
lastDragLocationbooleantrueKeeps the last dragged size after closing and reopening.
classNamestringundefinedAdds custom classes to the drawer element.
zIndexnumber1050Base stacking value for the drawer and backdrop.
ariaLabelstring"Drawer"Accessible dialog label.
onOpen(instance) => voidundefinedRuns after the drawer opens.
onClose(instance) => voidundefinedRuns after the drawer closes.
onDragStart(instance) => voidundefinedRuns when resize dragging starts.
onDrag(size, instance) => voidundefinedRuns during drag updates.
onDragEnd(size, instance) => voidundefinedRuns when resize dragging ends.
onDestroy(instance) => voidundefinedRuns when the instance is destroyed.

Methods

After you create an instance, these methods drive the drawer programmatically.

MethodHow it works
open()Opens the drawer and moves focus into it.
close()Closes the drawer and restores focus when possible.
toggle()Switches between open and closed state.
destroy()Removes DOM, listeners, and runs destroy hooks.
setContent(content)Replaces the drawer content with HTML or an element.
setPosition(position)Moves the drawer to another edge.
setSize(size)Applies a new size value.
getSize()Returns the current size string.
isOpen()Returns whether the drawer is currently open.

Custom events

The core package dispatches these events from the original parent container, which makes it easy to integrate with plain DOM code or analytics hooks.

EventDetail
tiny-drawer:open{ instance }
tiny-drawer:close{ instance }
tiny-drawer:drag-start{ instance }
tiny-drawer:drag{ instance, size }
tiny-drawer:drag-end{ instance, size }
tiny-drawer:destroy{ instance }

React props

These props are available on the TinyDrawer component from tiny-drawer-react.

PropTypeDefaultHow it works
openbooleanundefinedControlled open state.
defaultOpenbooleanfalseInitial uncontrolled state.
onOpenChange(open: boolean) => voidundefinedReceives state changes from user actions and imperative APIs.
positionDrawerPositionvanilla defaultUpdates placement through instance.setPosition().
sizeDrawerSizeValuevanilla defaultUpdates size through instance.setSize().
minSizeDrawerSizeValuevanilla defaultPassed through to the core package.
maxSizeDrawerSizeValuevanilla defaultPassed through to the core package.
parentContainerstring | HTMLElement | nullnullOptional parent mount target for the underlying instance.
themePrefixstringundefinedPassed through to the core package.
backdropbooleanundefinedPassed through to the core package.
closeButtonbooleanundefinedPassed through to the core package.
closeOnBackdropbooleanundefinedPassed through to the core package.
outSideClickClosebooleanundefinedCloses the drawer when the user clicks outside its mounted boundary.
closeOnEscapebooleanundefinedPassed through to the core package.
draggablebooleanundefinedPassed through to the core package.
onScrollFullboolean | DrawerScrollFullOptionsundefinedEnables scroll-to-full behavior and supports the 1.2.0 object API with backDrop, drawer, and nested scrollTarget. In React, prefer a stable object reference instead of an inline object when the page re-renders often.
fullScreenGapDrawerSizeValueundefinedControls the gap preserved while the drawer expands to full size.
animationbooleanundefinedPassed through to the core package.
appendToBodybooleanundefinedPassed through to the core package.
lastDragLocationbooleanundefinedPassed through to the core package.
classNamestringundefinedCustom class applied to the drawer element.
zIndexnumberundefinedPassed through to the core package.
ariaLabelstringundefinedPassed through to the core package.
childrenReact.ReactNodeundefinedRendered into the internal content portal.
containerstring | HTMLElement | nullnullUses an external host container when supplied.
containerClassNamestringundefinedApplied to the internal host container when one is rendered.
containerStyleReact.CSSPropertiesundefinedInline styles for the internal host container.
destroyOnUnmountbooleantrueControls whether the wrapper destroys the instance during unmount.
restoreFocusbooleantrueRestores focus after close when possible.
onOpen(instance) => voidundefinedVanilla open callback passthrough.
onClose(instance) => voidundefinedVanilla close callback passthrough.
onDragStart(instance) => voidundefinedVanilla drag start callback passthrough.
onDrag(size, instance) => voidundefinedVanilla drag callback passthrough.
onDragEnd(size, instance) => voidundefinedVanilla drag end callback passthrough.
onDestroy(instance) => voidundefinedVanilla destroy callback passthrough.

Behavior notes

Bottom drawers grow upward, top drawers grow downward, left drawers grow rightward, and right drawers grow leftward. Percentage sizes resolve from the mounted parent container when embedded, and from the viewport when the drawer is body-mounted.

When onScrollFull is enabled, drag resizing is disabled and the drawer expands once the chosen scroll target moves beyond the top threshold. In 1.2.0, pass an object to onScrollFull when you want separate control over backDrop, drawer, and a nested scrollTarget. Use fullScreenGap to preserve space from the opposite edge.

In React, avoid writing onScrollFull={{ backDrop: true, drawer: true }}directly inside JSX when the parent re-renders frequently. That creates a fresh object every render, which can cause the wrapper to re-sync scroll-full behavior and lead to visible flicker in some layouts. Prefer a shared constant or useMemo().

Accessibility behavior includes role="dialog", aria-modal, escape-key close support, focus moving into the drawer on open, and focus restoration on close when possible.