import {Overlay} from '@primer/react'
The Overlay
component handles all behaviors needed by overlay UIs as well as the common styles that all overlays should have. Overlay
is the base component for many of our overlay-type components. Overlays use shadows to express elevation.
Behaviors include:
Escape
Overlay
must either have:aria-labelledby
attribute that refers to a visible title.aria-label
attributeOverlay
should also have a longer description, use aria-describedby
Overlay
component has a role="dialog"
set on it, if you are using Overlay
for alerts, you can pass in role="alertdialog"
instead. Please read the W3C guidelines to determine which role is best for your use caseOverlay
component has aria-modal
set to true
by default and should not be overridden as all Overlay
s behave as modals.See the W3C accessibility recommendations for modals.
Overlay
renders its children
within a div positioned absolutely within a portal within the default portal root. The overlay will not update its positioning if the portal root's positioning changes (e.g., if the portal root is statically positioned after some DOM element that dynamically resizes). You may consider using the AnchoredOverlay component or customizing the portal root to achieve different positioning behavior.
The position of the Overlay can be customized by using the position
prop in conjunction with the top|left|right|bottom
props.
Name | Type | Default | Description |
---|---|---|---|
returnFocusRef Required | React.RefObject<HTMLElement> | Ref for the element to focus when the | |
onClickOutside Required | function | Function to call when clicking outside of the | |
onEscape Required | function | Function to call when user presses | |
ignoreClickRefs | React.RefObject<HTMLElement> [] | An array of ref objects to ignore clicks on in the onOutsideClick behavior. This is often used to ignore clicking on the element that toggles the open/closed state for the Overlay to prevent the Overlay from being toggled twice. | |
initialFocusRef | React.RefObject<HTMLElement> | Ref for the element to focus when the | |
width | | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge' | 'auto' | 'auto' | Sets the width of the |
height | | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'auto' | 'auto' | Sets the height of the |
maxHeight | | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | Sets the maximum height of the | |
maxWidth | | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | Sets the maximum width of the | |
visibility | | 'visible' | 'hidden' | 'visible' | Sets the visibility of the |
anchorSide | | 'inside-top' | 'inside-bottom' | 'inside-left' | 'inside-right' | 'inside-center' | 'outside-top' | 'outside-bottom' | 'outside-left' | 'outside-right' | If provided, the Overlay will slide into position from the side of the anchor with a brief animation | |
top | number | 0 | The top CSS property of the Overlay — affects the vertical position. |
left | number | 0 | The left CSS property of the Overlay — affects the horizontal position. |
right | number | The right CSS property of the Overlay — affects the horizontal position. | |
bottom | number | The bottom CSS property of the Overlay — affects the vertical position. | |
position | | 'static' | 'relative' | 'absolute' | 'fixed' | 'sticky' | absolute | The position CSS property of the Overlay — sets how the Overlay is positioned relative to its Portal |
portalContainerName | string | If defined, Overlays will be rendered in the named portal. See also | |
sx | SystemStyleObject |