Modal

Maintainer:
amje
GitHub
disableBodyScrollLock
import {Modal} from '@gravity-ui/uikit';

The Modal component serves as base for creating pop-up windows with a backdrop above the rest of the content on a page. It disables scrolling while opening and manages focus for content. The Modal child components are rendered inside the Portal component. With Modal, you can implement dialogs, alerts, confirmations, and more.

Usage

import {useState} from 'react';
import {Button, Modal} from '@gravity-ui/uikit';

const [open, setOpen] = useState(false);

<Button onClick={() => setOpen(true)}>Open Modal</Button>
<Modal open={open} onClose={() => setOpen(false)}>
    Content
</Modal>

Properties

NameDescriptionTypeDefault
autoFocusWhile open, the focus will be set to the first interactive element in the contentbooleantrue
childrenAny React contentReact.ReactNode
classNameclass HTML attribute for the root nodestring
containerDOM element to which component is mounted via PortalHTMLElementdocument.body
contentClassNameclass HTML attribute for the content nodestring
disableBodyScrollLockDisables locking scroll while openbooleanfalse
disableEscapeKeyDownDisables triggering close on Escbooleanfalse
disableOutsideClickDisables triggering close on outside clicksbooleanfalse
disablePortalDisables using Portalbooleanfalse
focusTrapEnables focus trapping behaviorbooleantrue
keepMountedModal will not be removed from the DOM upon hidingbooleanfalse
onCloseHandles Modal close eventFunction
onEnterKeyDownEnter press event handlerFunction
onEscapeKeyDownEsc press event handlerFunction
onTransitionEnterOpen transition start event handlerFunction
onTransitionExitClose transition start event handlerFunction
onTransitionEnteredOpen transition end event handlerFunction
onTransitionExitedClose transition end event handlerFunction
onOutsideClickOutside click event handlerFunction
openManages Modal visibilitybooleanfalse
qaTest attribute (data-qa)string
restoreFocusRefElement the focus will be restored toReact.RefObject
stylestyle HTML attribute for the root nodestring
aria-labelaria-label HTML attribute to describe Modalstring
aria-labelledbyID of the visible Modal caption elementstring
contentOverflowDetermines whether the Modal has a scroll indicator inside or gets larger with the contentvisible autovisible

CSS API

NameDescription
--g-modal-marginMargin around the Modal content
--g-modal-border-radiusModal content border radius
--g-modal-widthModal content width
--g-modal-heightModal content height