Components
An overlay that contains content and covers the page
Version: | 14.18.2 •View source•Changelog•Report issue | |
---|---|---|
Install: | yarn add @thumbtack/thumbprint-react | |
Import: | import { ModalCurtain } from '@thumbtack/thumbprint-react'; |
Before using this component…
ModalCurtain
is a low-level component that should only be used if the Modal component is too restrictive. Please reach out to the Design Systems team before using it.
The ModalCurtain
component makes it easy to create an accessible overlay that contains content and covers the page. It contains a few powerful features:
children
. Trap the focus within the ModalCurtain
while it is open, preventing users from accidentally tabbing to the page underneath.ModalCurtain
is open.</body>
tag. This greatly decreases the chance of running into z-index issues.ModalCurtain
if the user presses Esc.ModalCurtain
click: Make it easy to close the modal if the ModalCurtain
is clicked on.The ModalCurtain
component CSS handles positioning, overflow, z-index, visibility, and opacity. It does not include background colors, padding, transitions, or other opinionated styles since the component was designed to be versatile.
ModalCurtain
with a basic modalThis example contains a ModalCurtain
with a basic modal and no transition. Because there is no transition, the stage
prop only cycles between entered
and exited
.
ModalCurtain
with a custom initial focusBy default the curtain will focus on the container when it opens. If your modal contains a focusable input, you may wish to skip directly to this. Pass a selector for an element in the modal’s children
to initialFocus
to acheive this.
ModalCurtain
with a full screen takeoverThe ModalCurtain
component works well for full-screen takeovers. This example doesn’t use curtainOnClick
since we don’t want to close the curtain when clicking on the backdrop.
onCloseClick
Function that fires to close the modal.
() => void
children
Content that appears on top of the curtain. children
is a render
prop and expects a function. The function
provided receives an object two properties:
curtainClassName
: Handles positioning, z-index, opacity, overflow, and visibility.
Should be added to the className
of the outermost element within the children
.curtainOnClick
: You can optionally add this prop to the onClick
of an element within
children
. This is typically used on to close a ModalCurtain when clicking on a dark
backdrop.The examples on this page include code samples that demonstrate real use of these props.
({
curtainClassName,
curtainOnClick,
}: {
curtainClassName: string;
curtainOnClick: (event: React.MouseEvent<HTMLElement>) => void;
}) => JSX.Element
stage
The four states that a modal can be in.
exited
– Modal is fully closedentering
– Modal is openingentered
– Modal has fully openexiting
– Modal is closingModals that do not have transitions will only use the entered
and exited
stages.
This prop can be one of the following 5 types:
'entering'
'entered'
'exiting'
'exited'
null
'exited'
accessibilityLabel
Accessibility title used to describe the content of the modal to screen readers.
string
'Modal'
shouldCloseOnEscape
Determines if the modal should close when pressing the escape key.
boolean
true
initialFocus
The element that should be focused when the modal opens. If omitted, the entire container element of the modal is focused.
This prop can be one of the following 2 types:
HTMLElement
null