scroll locking
Stopping the page behind an overlay from scrolling, usually by setting overflow: hidden on the body while the overlay is open.
In more detail
The previous overflow value must be saved and restored when the overlay closes, typically in a useEffect cleanup function. Otherwise the page stays unscrollable after the dialog is gone.
Related terms
- overflow — The CSS property that decides what happens to content that does not fit in its box: show it, clip it or scroll it.
- useEffect — The React hook for running side work, such as adding listeners or changing document.body, after a component renders.
- modal dialog — A window laid over the page that users must deal with before returning to the page beneath, with role="dialog" and aria-modal="true".
Taught in
- Overlay Architecture: Portals, Stacking Contexts & Backdrops — Design Systems & Component Engineering