Skip to content

Commit 5bdf783

Browse files
committed
feat(RAC): expose --page-width and --visual-viewport-width from Modal
1 parent 4c91299 commit 5bdf783

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,22 @@ function ModalOverlayInner({UNSTABLE_portalContainer, ...props}: ModalOverlayInn
184184
});
185185

186186
let viewport = useViewportSize();
187+
let pageWidth: number | undefined = undefined;
187188
let pageHeight: number | undefined = undefined;
188189
if (typeof document !== 'undefined') {
189190
let scrollingElement = isScrollable(document.body) ? document.body : document.scrollingElement || document.documentElement;
190-
// Prevent Firefox from adding scrollbars when the page has a fractional height.
191+
// Prevent Firefox from adding scrollbars when the page has a fractional width/height.
192+
let fractionalWidthDifference = scrollingElement.getBoundingClientRect().width % 1;
191193
let fractionalHeightDifference = scrollingElement.getBoundingClientRect().height % 1;
194+
pageWidth = scrollingElement.scrollWidth - fractionalWidthDifference;
192195
pageHeight = scrollingElement.scrollHeight - fractionalHeightDifference;
193196
}
194197

195198
let style = {
196199
...renderProps.style,
200+
'--visual-viewport-width': viewport.width + 'px',
197201
'--visual-viewport-height': viewport.height + 'px',
202+
'--page-width': pageWidth !== undefined ? pageWidth + 'px' : undefined,
198203
'--page-height': pageHeight !== undefined ? pageHeight + 'px' : undefined
199204
};
200205

0 commit comments

Comments
 (0)