Skip to content

Vben Modal

Vben Modal is the shared modal wrapper used by the framework. It supports draggable behavior, fullscreen mode, auto-height handling, loading state, connected components, and an imperative API.

Basic Usage

ts
const [Modal, modalApi] = useVbenModal({
  // props
  // events
});

Current Usage Notes

  • If you use connectedComponent, the inner and outer components share data through modalApi.setData() and modalApi.getData().
  • When connectedComponent is present, avoid pushing extra modal props through the connected side. Prefer useVbenModal(...) or modalApi.setState(...).
  • Default modal behavior can be adjusted in apps/<app>/src/bootstrap.ts through setDefaultModalProps(...).

Key Props

PropDescriptionType
appendToMainmount inside the main content area instead of bodyboolean
connectedComponentconnect an inner component to the modal wrapperComponent
animationTypemodal enter/leave animation'slide' | 'scale'
fullscreenButtonshow or hide the fullscreen toggleboolean
overlayBlurblur amount for the overlaynumber
submittinglock modal interactions while submittingboolean

Events

EventDescriptionType
onBeforeClosecalled before close; returning false or rejecting prevents close() => Promise<boolean | undefined> | boolean | undefined
onOpenChangecalled when open state changes(isOpen: boolean) => void
onOpenedcalled after open animation completes() => void
onClosedcalled after close animation completes() => void

modalApi

MethodDescription
setState(...)updates modal state
open()opens the modal
close()closes the modal
setData(data)stores shared data
getData<T>()reads shared data
lock(isLocked = true)locks the modal into submitting state
unlock()alias for lock(false)

Contributors

The avatar of contributor named as xingyu4j xingyu4j

Changelog

Released under the MIT License.