How to use
Backdrop is the overlay primitive Modal and Drawer are both built on — a portaled, focus-trapping dim/blur layer behind arbitrary content. Reach for Modal or Drawer for their pre-built header/body/footer chrome; reach for Backdrop directly when you need the overlay behavior (stacking, focus trap, scroll lock, dismissal) around something with a fully custom layout.
import { Backdrop, Button } from "oks-ui";Same controlled shape as Modal/Drawer — isOpen and onClose are both required, and children is whatever you want rendered above the dimmed backdrop, with total control over its layout instead of Modal's fixed header/body/footer slots.
function ImageLightbox({ src, isOpen, onClose }: { src: string; isOpen: boolean; onClose: () => void }) {
return (
<Backdrop isOpen={isOpen} onClose={onClose} blur="lg">
<img src={src} alt="" className="max-h-[90vh] max-w-[90vw] rounded-lg" />
</Backdrop>
);
}blur accepts true (a sensible default), a size token, or a raw pixel number for the backdrop-filter blur amount. backgroundColor and backgroundOpacity control the dim layer's tint independently of the blur, for anything from a near-black scrim to a subtle, barely-there overlay.
<Backdrop isOpen={isOpen} onClose={onClose} blur="sm" backgroundOpacity={60}>
{content}
</Backdrop>animationType picks how the backdrop and its content enter/exit (fade, zoom, or a directional slide), with animationDuration/easing to fine-tune the feel — the same animation system Modal and Drawer forward their own animation props into internally.
<Backdrop isOpen={isOpen} onClose={onClose} animationType="zoom" animationDuration={0.2}>
{content}
</Backdrop>By default the content wrapper sizes to its content and centers within the backdrop. Set contentFullSize to stretch it to fill the backdrop instead — useful for a custom overlay that needs to manage its own internal layout/scrolling edge to edge, like a full-viewport image gallery.
All available props for Backdrop. See the full component page for an interactive playground.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Content rendered above the backdrop. |
children
ReactNode
Default: —
Content rendered above the backdrop.
| Prop | Type | Default | Description |
|---|---|---|---|
blur | boolean | "sm" | "md" | "lg" | number | true (8px) | Backdrop blur amount. |
backgroundColor | string | "var(--oks-palette-neutral-950, #000)" | Backdrop tint color. |
backgroundOpacity | number | 80 | Backdrop opacity (0-100). |
blur
boolean | "sm" | "md" | "lg" | number
Default: true (8px)
Backdrop blur amount.
backgroundColor
string
Default: "var(--oks-palette-neutral-950, #000)"
Backdrop tint color.
backgroundOpacity
number
Default: 80
Backdrop opacity (0-100).
| Prop | Type | Default | Description |
|---|---|---|---|
zIndex | number | — | Explicit stacking z-index; auto-computed per overlay depth when unset. |
portal | boolean | true | Renders through a React portal. |
container | Element | DocumentFragment | null | — | Custom portal mount target. |
contentFullSize | boolean | false | Stretches the content wrapper to fill the backdrop. |
zIndex
number
Default: —
Explicit stacking z-index; auto-computed per overlay depth when unset.
portal
boolean
Default: true
Renders through a React portal.
container
Element | DocumentFragment | null
Default: —
Custom portal mount target.
contentFullSize
boolean
Default: false
Stretches the content wrapper to fill the backdrop.
| Prop | Type | Default | Description |
|---|---|---|---|
isOpen | boolean | — | Controls whether the backdrop is open (required). |
closeOnOutsideClick | boolean | true | Closes when clicking outside the content. |
closeOnEscape | boolean | true | Closes on Escape. |
lockScroll | boolean | true | Locks body scroll while open. |
trapFocus | boolean | true | Traps keyboard focus within the content while open. |
isOpen
boolean
Default: —
Controls whether the backdrop is open (required).
closeOnOutsideClick
boolean
Default: true
Closes when clicking outside the content.
closeOnEscape
boolean
Default: true
Closes on Escape.
lockScroll
boolean
Default: true
Locks body scroll while open.
trapFocus
boolean
Default: true
Traps keyboard focus within the content while open.
| Prop | Type | Default | Description |
|---|---|---|---|
animationDuration | number | 0.3 | Enter/exit animation duration in seconds. |
animationType | "fade" | "zoom" | "slideUp" | "slideDown" | "slideLeft" | "slideRight" | fade | Entrance/exit animation. |
easing | "ease" | "easeIn" | "easeOut" | "easeInOut" | ease | Animation easing curve. |
animationDuration
number
Default: 0.3
Enter/exit animation duration in seconds.
animationType
"fade" | "zoom" | "slideUp" | "slideDown" | "slideLeft" | "slideRight"
Default: fade
Entrance/exit animation.
easing
"ease" | "easeIn" | "easeOut" | "easeInOut"
Default: ease
Animation easing curve.
| Prop | Type | Default | Description |
|---|---|---|---|
onClose | () => void | — | Called to close the backdrop (required). |
onClose
() => void
Default: —
Called to close the backdrop (required).
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Class applied to the backdrop layer. |
style | CSSProperties | — | Inline styles for the backdrop layer. |
contentClassName | string | — | Class applied to the content wrapper. |
contentStyle | CSSProperties | — | Inline styles for the content wrapper. |
className
string
Default: —
Class applied to the backdrop layer.
style
CSSProperties
Default: —
Inline styles for the backdrop layer.
contentClassName
string
Default: —
Class applied to the content wrapper.
contentStyle
CSSProperties
Default: —
Inline styles for the content wrapper.