Skip to content

Commit c54c7e5

Browse files
committed
fix: Use 'combinedRef'. Omit overriden 'overlayRef'. Imperatively set height.
1 parent eb298ad commit c54c7e5

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/Overlay.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const heightMap = {
1919
medium: '320px',
2020
large: '432px',
2121
xlarge: '600px',
22-
auto: 'auto'
22+
auto: 'auto',
23+
initial: 'auto' // Passing 'initial' initially applies 'auto'
2324
}
2425

2526
const widthMap = {
@@ -68,7 +69,7 @@ export type OverlayProps = {
6869
onClickOutside: (e: TouchOrMouseEvent) => void
6970
onEscape: (e: KeyboardEvent) => void
7071
visibility?: 'visible' | 'hidden'
71-
height?: keyof typeof heightMap | 'initial'
72+
height?: keyof typeof heightMap
7273
[additionalKey: string]: unknown
7374
} & Omit<ComponentProps<typeof StyledOverlay>, 'height' | 'visibility' | keyof SystemPositionProps>
7475

@@ -103,7 +104,7 @@ const Overlay = React.forwardRef<HTMLDivElement, OverlayProps>(
103104
const overlayRef = useRef<HTMLDivElement>(null)
104105
const combinedRef = useCombinedRefs(overlayRef, forwardedRef)
105106

106-
const overlayProps = useOverlay({
107+
useOverlay({
107108
overlayRef,
108109
returnFocusRef,
109110
onEscape,
@@ -112,18 +113,16 @@ const Overlay = React.forwardRef<HTMLDivElement, OverlayProps>(
112113
initialFocusRef
113114
})
114115

115-
const initialHeight = useRef<string>('auto')
116116
useEffect(() => {
117-
if (overlayRef.current?.clientHeight) {
118-
initialHeight.current = `${overlayRef.current.clientHeight}px`
117+
if (heightKey === 'initial' && combinedRef.current?.clientHeight) {
118+
combinedRef.current.style.height = `${combinedRef.current.clientHeight}px`
119119
}
120-
}, [overlayRef])
121-
const height = heightKey === 'initial' ? initialHeight.current : heightMap[heightKey || 'auto']
120+
}, [heightKey, combinedRef])
121+
const height = heightMap[heightKey || 'auto']
122122

123123
return (
124124
<Portal>
125125
<StyledOverlay
126-
{...overlayProps}
127126
aria-modal="true"
128127
role={role}
129128
height={height}

0 commit comments

Comments
 (0)