Skip to content

Commit b2f3515

Browse files
devongovettLFDanLu
andauthored
fix: Height of modal underlay is incorrect when the body has height: 100% (#8958)
* fix: Height of modal underlay is incorrect when the body has height: 100% * Turn on verdaccio * Maybe more accurate fractional height * Revert "Turn on verdaccio" This reverts commit 5420894. * No undefinedpx * Revert "Revert "Turn on verdaccio"" This reverts commit 21740c3. * Revert "Revert "Revert "Turn on verdaccio""" This reverts commit 42cb451. --------- Co-authored-by: Daniel Lu <[email protected]>
1 parent 0bc8b24 commit b2f3515

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

packages/@react-spectrum/overlays/src/Underlay.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
import {classNames} from '@react-spectrum/utils';
14+
import {isScrollable} from '@react-aria/utils';
1415
import React, {JSX} from 'react';
1516
import underlayStyles from '@adobe/spectrum-css-temp/components/underlay/vars.css';
1617

@@ -20,12 +21,20 @@ interface UnderlayProps {
2021
}
2122

2223
export function Underlay({isOpen, isTransparent, ...otherProps}: UnderlayProps): JSX.Element {
24+
let pageHeight: number | undefined = undefined;
25+
if (typeof document !== 'undefined') {
26+
let scrollingElement = isScrollable(document.body) ? document.body : document.scrollingElement || document.documentElement;
27+
// Prevent Firefox from adding scrollbars when the page has a fractional height.
28+
let fractionalHeightDifference = scrollingElement.getBoundingClientRect().height % 1;
29+
pageHeight = scrollingElement.scrollHeight - fractionalHeightDifference;
30+
}
31+
2332
return (
2433
<div
2534
data-testid="underlay"
2635
{...otherProps}
2736
// Cover the entire document so iOS 26 Safari doesn't clip the underlay to the inner viewport.
28-
style={{height: typeof document !== 'undefined' ? document.body.getBoundingClientRect().height : undefined}}
37+
style={{height: pageHeight}}
2938
className={classNames(underlayStyles, 'spectrum-Underlay', {
3039
'is-open': isOpen,
3140
'spectrum-Underlay--transparent': isTransparent

packages/react-aria-components/src/Modal.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import {AriaModalOverlayProps, DismissButton, Overlay, useIsSSR, useModalOverlay} from 'react-aria';
1414
import {ContextValue, Provider, RenderProps, SlotProps, useContextProps, useRenderProps} from './utils';
1515
import {DOMAttributes, forwardRefType, GlobalDOMAttributes, RefObject} from '@react-types/shared';
16-
import {filterDOMProps, mergeProps, mergeRefs, useEnterAnimation, useExitAnimation, useObjectRef, useViewportSize} from '@react-aria/utils';
16+
import {filterDOMProps, isScrollable, mergeProps, mergeRefs, useEnterAnimation, useExitAnimation, useObjectRef, useViewportSize} from '@react-aria/utils';
1717
import {OverlayTriggerProps, OverlayTriggerState, useOverlayTriggerState} from 'react-stately';
1818
import {OverlayTriggerStateContext} from './Dialog';
1919
import React, {createContext, ForwardedRef, forwardRef, useContext, useMemo, useRef} from 'react';
@@ -171,10 +171,18 @@ function ModalOverlayInner({UNSTABLE_portalContainer, ...props}: ModalOverlayInn
171171
});
172172

173173
let viewport = useViewportSize();
174+
let pageHeight: number | undefined = undefined;
175+
if (typeof document !== 'undefined') {
176+
let scrollingElement = isScrollable(document.body) ? document.body : document.scrollingElement || document.documentElement;
177+
// Prevent Firefox from adding scrollbars when the page has a fractional height.
178+
let fractionalHeightDifference = scrollingElement.getBoundingClientRect().height % 1;
179+
pageHeight = scrollingElement.scrollHeight - fractionalHeightDifference;
180+
}
181+
174182
let style = {
175183
...renderProps.style,
176184
'--visual-viewport-height': viewport.height + 'px',
177-
'--page-height': typeof document !== 'undefined' ? document.body.getBoundingClientRect().height + 'px' : undefined
185+
'--page-height': pageHeight !== undefined ? pageHeight + 'px' : undefined
178186
};
179187

180188
return (

0 commit comments

Comments
 (0)