Usage
Remove title and close button
You can remove modal title and close button. It will still be possible to close modal by clicking on overlay or pressing escape.
Center modal vertically
Change size
You can change modal width by setting size
prop to predefined size or any valid width, for example, 55% or 200px.
Size controls modal width, max-width is set to 100% with spacing on left and right, no matter what size
is passed 100% will not be exceeded:
Customize overlay
Modal uses Overlay component, you can change overlay opacity, blur and color:
Modal with overflow
You can control modal vertical overflow behavior by setting overflow
prop:
Change transitions
Modal is built with Transition component.
You can change transitions with props:
- transition – predefined transition name or transition object
- transitionDuration – transition duration in ms, defaults to 300ms. Note that, modal has two elements which are animated: overlay and modal body. Overlay changes opacity during transition and its animation is twice as fast as modal body.
- transitionTimingFunction – timing function, defaults to
theme.transitionTimingFunction
Initial focus
Modal uses use-focus-trap to manage focus.
To specify initial focus element add data-autofocus
attribute:
Control behavior
The following props can be used to control Modal behavior. In most cases you should not turn these features off as it will make your modal less accessible.
trapFocus
– defines whether focus should be trapped inside modalcloseOnEscape
– defines whether modal should be closed when user pressesEscape
keycloseOnClickOutside
– defines whether modal should be closed when user clicks outside of modal body
Accessibility and usability
- When modal is opened, focus is trapped inside and vertical scroll is locked at current position
- When user clicks on overlay or presses escape modal closes
- Modal transitions are disabled if user prefers to reduce motion
- Modal wrapper has
aria-modal="true"
androle="dialog"
attributes - Modal wrapper has
aria-labelledby
andaria-describedby
pointing to modal title and body
For better screen reader support set closeButtonLabel
prop: