Modal

An accessible overlay dialog for displaying content that requires user attention.

Import

import { Modal } from '@tidbcloud/uikit'

Basic Usage

import { useDisclosure } from '@tidbcloud/uikit-hooks'
import { Modal, Button } from '@tidbcloud/uikit'
 
function Demo() {
  const [opened, { open, close }] = useDisclosure(false)
 
  return (
    <>
      <Modal opened={opened} onClose={close} title="Authentication">
        {/* Modal content */}
      </Modal>
 
      <Button onClick={open}>Open modal</Button>
    </>
  )
}

Centered Modal

import { useDisclosure } from '@tidbcloud/uikit-hooks'
import { Modal, Button } from '@tidbcloud/uikit'
 
function Demo() {
  const [opened, { open, close }] = useDisclosure(false)
 
  return (
    <>
      <Modal opened={opened} onClose={close} title="Authentication" centered>
        {/* Modal content */}
      </Modal>
 
      <Button onClick={open}>Open centered Modal</Button>
    </>
  )
}

Fullscreen Modal

import { useDisclosure } from '@tidbcloud/uikit-hooks'
import { Modal, Button } from '@tidbcloud/uikit'
 
function Demo() {
  const [opened, { open, close }] = useDisclosure(false)
 
  return (
    <>
      <Modal
        opened={opened}
        onClose={close}
        title="Fullscreen modal"
        fullScreen
        transitionProps={{ transition: 'fade', duration: 200 }}
      >
        {/* Modal content */}
      </Modal>
 
      <Button onClick={open}>Open fullscreen modal</Button>
    </>
  )
}

Without Header

import { Modal } from '@tidbcloud/uikit'
 
function Demo() {
  return (
    <Modal opened={true} onClose={() => {}} withCloseButton={false}>
      Modal without header, press escape or click on overlay to close
    </Modal>
  )
}

Customize Overlay

import { Modal } from '@tidbcloud/uikit'
 
function Demo() {
  return (
    <Modal
      opened={true}
      onClose={() => {}}
      title="Authentication"
      overlayProps={{
        backgroundOpacity: 0.55,
        blur: 3
      }}
    >
      {/* Modal content */}
    </Modal>
  )
}

Key Props

PropTypeDefaultDescription
openedboolean-Controls modal visibility
onClose() => void-Called when modal is closed
titleReactNode-Modal title
centeredboolean-Center modal vertically
fullScreenboolean-Make modal fullscreen
sizeMantineSize | number | string'md'Modal width (xs, sm, md, lg, xl, or any value)
radiusMantineRadius-Border radius
withCloseButtonbooleantrueShow/hide close button
closeButtonPropsCloseButtonProps-Props passed to the close button
closeOnClickOutsidebooleantrueClose on outside click
closeOnEscapebooleantrueClose on Escape key press
overlayPropsOverlayProps-Props for overlay customization
withOverlaybooleantrueDetermines whether overlay should be rendered
transitionPropsTransitionProps-Transition animation props
keepMountedbooleanfalseIf set, modal will not be unmounted when closed
lockScrollbooleantrueDetermines whether scroll should be locked
trapFocusbooleantrueDetermines whether focus should be trapped
returnFocusbooleantrueReturn focus to last active element on close
paddingMantineSpacing'md'Modal content padding
shadowMantineShadow'xl'Modal shadow
zIndexstring | number200z-index CSS property
xOffsetnumber | string-Horizontal content offset
yOffsetnumber | string-Vertical content offset