Skip to main content

Dialog

Informs the user and hosts related actions while preserving the current page state.

Basic usage​

Controlled dialog
import { useState } from 'react'
import { LhButton, LhDialog } from '@lh-ui/react'

export default function Demo() {
const [open, setOpen] = useState(false)

return (
<>
<LhButton type="primary" onClick={() => setOpen(true)}>
Open dialog
</LhButton>
<LhDialog
open={open}
title="Notice"
width="420px"
footer={
<>
<LhButton onClick={() => setOpen(false)}>Cancel</LhButton>
<LhButton type="primary" onClick={() => setOpen(false)}>OK</LhButton>
</>
}
onClose={() => setOpen(false)}
>
<p>This is a controlled dialog.</p>
</LhDialog>
</>
)
}

Dialog Props​

PropDescriptionTypeOptionsDefault
openWhether the dialog is open (fully controlled)boolean—false
titleTitle (also used as the aria-label fallback when there is no header)string——
widthWidthstring | number——
fullscreenFullscreenboolean—false
showCloseWhether to show the close buttonboolean—true
closeOnClickModalClose on modal clickboolean—true
closeOnPressEscapeClose on Escboolean—true
draggableDraggable (by the title bar)boolean—false
centerCenter the title and footerboolean—false
positionCustom positioning offsets{ top?: string; left?: string }——
lockScrollLock body scroll while openboolean—true
beforeCloseIntercept before closing (returning false / Promise<false> keeps it open)() => boolean | Promise<boolean>——
topDistance from the topstring——
zIndexz-index (by default assigned increasingly by useLhZIndex)number——
headerCustom header (overrides title)ReactNode——
footerCustom footerReactNode——
themeVarsComponent-level theme variablesRecord<string, string>——
sxShorthand layout propsSxProps——

Dialog events​

EventDescriptionCallback signatureVue equivalent
onCloseClose request (triggered by the modal / Esc / close button; not called if beforeClose intercepts)() => voidupdate:modelValue
onOpenEmitted the instant it opens (DOM mounted)() => void@open
onOpenedEmitted after the open transition ends() => void@opened
onCloseStartEmitted when the close transition begins() => void@close
onClosedEmitted after the close transition ends (DOM unmounted)() => void@closed

ref​

forwardRef<HTMLDivElement>. LhDialogInstance currently exposes no imperative methods.

Fully controlled semantics

Unlike plus, this library's Dialog has no internal isVisible intermediate state: open is held entirely by external state, and any close path only calls onClose. See the migration guide.

Esc with multiple overlays

useLhOverlayStack maintains an open-order stack, and Esc only closes the top overlay, preventing one keystroke from dismissing every overlay.

Styles​

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