Modal

Display popup content that requires attention or provides additional information. If you just need to prompt for a text message, try component Toast.

The Modal contain an additional Hooks, see subsection useModal for details.

General

Use visible control whether Modal is displayed.

With useModal

Use hooks for easier control Modal.

Without Actions

Hide all action buttons.

Disable Action

Disable one of the buttons.

Customized

Custom width or className.

Loading

You can use loading in Modal.Action with the property loading.

Overlong

Whether it is desktop or mobile, the content beyond the scope has been well handled.

APIs

Modal.Props

AttributeDescriptionTypeAccepted valuesDefault
visibleopen or closeboolean-false
onCloseopen event() => void--
onContentClickevent from modal content(e: MouseEvent) => void--
wrapClassNameclassName of the modal dialogstring--
keyboardpress Esc to close modalboolean-true
disableBackdropClickclick background and don't closeboolean-false
roleuse alertdialog for a message that needs an answer'dialog' / 'alertdialog'-dialog
aria-labelname of the dialog when there is no Modal.Titlestring--
...native propsHTMLAttributes'autoFocus', 'name', 'className', ...-

The dialog is named by Modal.Title and described by Modal.Subtitle on its own. Without a title, pass aria-label or aria-labelledby.

Modal.Title.Props

AttributeDescriptionTypeAccepted valuesDefault
...native propsHTMLAttributes'id', 'className', ...-

Modal.Subtitle.Props

AttributeDescriptionTypeAccepted valuesDefault
...native propsHTMLAttributes'id', 'className', ...-

Modal.Content.Props

AttributeDescriptionTypeAccepted valuesDefault
...native propsHTMLAttributes'id', 'className', ...-

Modal.Action.Props

AttributeDescriptionTypeAccepted valuesDefault
passivedisplay passive modeboolean-false
disableddisable current actionboolean-false
onClickclick handler(e: ModalActionEvent) => void--
loadingshow loadingboolean-false
...native propsButtonHTMLAttributes'id', 'className', ...-

useModal

type useModal = (initialVisible: boolean) => {
  visible: boolean
  setVisible: Dispatch<SetStateAction<boolean>>
  currentRef: MutableRefObject<boolean>
  bindings: {
    visible: boolean
    onClose: () => void
  }
}

ModalActionEvent

type ModalActionEvent = MouseEvent<HTMLButtonElement> & {
  close: () => void
}
Edit this page on GitHub