Skip to content

Commit

Permalink
Add role="dialog", focus trap to Overlay`
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerJDev committed Sep 19, 2024
1 parent 6c9121e commit cda82a1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/react/src/Overlay/Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {useRefObjectAsForwardedRef} from '../hooks/useRefObjectAsForwardedRef'
import type {AnchorSide} from '@primer/behaviors'
import {useTheme} from '../ThemeProvider'
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
import {useFocusTrap} from '../hooks/useFocusTrap'

type StyledOverlayProps = {
width?: keyof typeof widthMap
Expand Down Expand Up @@ -138,7 +139,7 @@ const Overlay = React.forwardRef<HTMLDivElement, OwnOverlayProps>(
(
{
onClickOutside,
role = 'none',
role,
initialFocusRef,
returnFocusRef,
ignoreClickRefs,
Expand Down Expand Up @@ -200,12 +201,16 @@ const Overlay = React.forwardRef<HTMLDivElement, OwnOverlayProps>(
// To be backwards compatible with the old Overlay, we need to set the left prop if x-position is not specified
const leftPosition: React.CSSProperties = left === undefined && right === undefined ? {left: 0} : {left}

const {containerRef} = useFocusTrap({

Check failure on line 204 in packages/react/src/Overlay/Overlay.tsx

View workflow job for this annotation

GitHub Actions / lint

'containerRef' is assigned a value but never used
containerRef: overlayRef, // only if `role="dialog"`, `aria-modal="true"` is true
})

return (
<Portal containerName={portalContainerName}>
<StyledOverlay
height={height}
width={width}
role={role}
role={role || 'dialog'}
{...rest}
ref={overlayRef}
style={
Expand Down

0 comments on commit cda82a1

Please sign in to comment.