[useScrollLock] Layout shift occurs with certain layouts #603
Labels
bug 🐛
Something doesn't work
component: dialog
This is the name of the generic UI component, not the React module!
The
useScrollLock
hook currently has issues:position: fixed
elements need to have theirwidth
orright
properties compensated by the removed scrollbar width, otherwise they shift over to the right once scroll locking is activated on the body. Regular content is unaffected. To complicate matters more, in some systems, the<body>
scrollbar appears on the left of the screen; this means theleft
property, if specified, would need to be compensated under certain conditions.overflow-y: scroll
is applied to the<body>
, the removed scrollbarpadding
compensation itself causes layout shift and needs to be ignored. There may be other layout settings where this is the case as well.radix-ui/primitives#1925
The
scrollbar-gutter: stable
CSS property, when applied to<html>
:Possible solutions
padding
compensation under certain layouts. However,position: fixed
will still need their layout adjusted for the removed scrollbar width. We need to add a CSS variable to the root such as--base-ui-removed-scrollbar-width
that users can use to apply to theirposition: fixed
elements:width: calc(100% - var(--base-ui-removed-scrollbar-width, 0px))
orright: var(--base-ui-removed-scrollbar-width, 0)
.Search keywords: scroll-lock
The text was updated successfully, but these errors were encountered: