Skip to content

Commit 393c8b0

Browse files
authored
fix: Use scrollbar-gutter: stable instead of padding in usePreventScroll (#8297)
1 parent 8d5d5d5 commit 393c8b0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/@react-aria/overlays/src/usePreventScroll.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ export function usePreventScroll(options: PreventScrollOptions = {}): void {
7171
// add some padding to prevent the page from shifting when the scrollbar is hidden.
7272
function preventScrollStandard() {
7373
return chain(
74-
setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}px`),
74+
// Use scrollbar-gutter when supported because it also works for fixed positioned elements.
75+
'scrollbarGutter' in document.documentElement.style
76+
? setStyle(document.documentElement, 'scrollbarGutter', 'stable')
77+
: setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}px`),
7578
setStyle(document.documentElement, 'overflow', 'hidden')
7679
);
7780
}

0 commit comments

Comments
 (0)