Skip to content

Commit eb770c8

Browse files
committed
fix: Imperatively-setting height allows us to realign the internal and external contract; 'height' is not widened to 'string' in the former, because arbitrary pixel values are no longer passed via props.
1 parent c54c7e5 commit eb770c8

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/Overlay.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {useCombinedRefs} from './hooks/useCombinedRefs'
99

1010
type StyledOverlayProps = {
1111
width?: keyof typeof widthMap
12-
height?: string
12+
height?: keyof typeof heightMap
1313
visibility?: 'visible' | 'hidden'
1414
}
1515

@@ -39,7 +39,7 @@ const StyledOverlay = styled.div<StyledOverlayProps & SystemCommonProps & System
3939
position: absolute;
4040
min-width: 192px;
4141
max-width: 640px;
42-
height: ${props => props.height};
42+
height: ${props => heightMap[props.height || 'auto']};
4343
width: ${props => widthMap[props.width || 'auto']};
4444
border-radius: 12px;
4545
overflow: hidden;
@@ -69,9 +69,8 @@ export type OverlayProps = {
6969
onClickOutside: (e: TouchOrMouseEvent) => void
7070
onEscape: (e: KeyboardEvent) => void
7171
visibility?: 'visible' | 'hidden'
72-
height?: keyof typeof heightMap
7372
[additionalKey: string]: unknown
74-
} & Omit<ComponentProps<typeof StyledOverlay>, 'height' | 'visibility' | keyof SystemPositionProps>
73+
} & Omit<ComponentProps<typeof StyledOverlay>, 'visibility' | keyof SystemPositionProps>
7574

7675
/**
7776
* An `Overlay` is a flexible floating surface, used to display transient content such as menus,
@@ -96,7 +95,7 @@ const Overlay = React.forwardRef<HTMLDivElement, OverlayProps>(
9695
ignoreClickRefs,
9796
onEscape,
9897
visibility,
99-
height: heightKey,
98+
height,
10099
...rest
101100
},
102101
forwardedRef
@@ -114,11 +113,10 @@ const Overlay = React.forwardRef<HTMLDivElement, OverlayProps>(
114113
})
115114

116115
useEffect(() => {
117-
if (heightKey === 'initial' && combinedRef.current?.clientHeight) {
116+
if (height === 'initial' && combinedRef.current?.clientHeight) {
118117
combinedRef.current.style.height = `${combinedRef.current.clientHeight}px`
119118
}
120-
}, [heightKey, combinedRef])
121-
const height = heightMap[heightKey || 'auto']
119+
}, [height, combinedRef])
122120

123121
return (
124122
<Portal>

0 commit comments

Comments
 (0)