1.0.1 • Published 6 months ago

@michellocana/react-scrolllock v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

React Scroll Lock

🚨 Not Maintained No Maintenance Intended

This project is a fork of react-scrolllock, which is now unmantained. This version keeps almost all of the original code, but updates the react and react-dom peer dependencies and moves from Flow to TypeScript.

Prevent scroll on the <body /> when a component is mounted.

Install

yarn add react-scrolllock

Usage

import { ScrollLock, TouchScrollable } from 'react-scrolllock'

class Modal extends Component {
  state = { lockScroll: false }
  render() {
    return (
      <div>
        ... // the lock accepts a single child element, which supports touch-scrolling.
        <ScrollLock>
          <ElementWithScrollableContent>...</ElementWithScrollableContent>
        </ScrollLock>
        // if your app structure doesn't allow wrapping like above, the `TouchScrollable` // component is exposed as a
        named export.
        <ScrollLock />
        <TouchScrollable>
          <ElementWithScrollableContent>...</ElementWithScrollableContent>
        </TouchScrollable>
        // you can also toggle the lock based on some state.
        <ScrollLock isActive={this.state.lockScroll} />
      </div>
    )
  }
}

Props

ScrollLock

PropertyDescription
accountForScrollbars booleanDefault: true -- Whether or not to replace the scrollbar width when active.
isActive booleanDefault: true -- Whether or not the lock is active.
children elementDefault: null -- This element is wrapped internally by the TouchScrollable component.

TouchScrollable

Wrap an element in the TouchScrollable component if you need an area that supports scroll on mobile.

This is necessary because the touchmove event is explicitly cancelled iOS doesn't observe overflow: hidden; when applied to the <body /> element 😢

PropertyDescription-
children elementref => elementRequired The element that can be scrolled.
1.0.1

6 months ago

1.0.0

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago