5.0.1 • Published 4 years ago

react-scrolllock v5.0.1

Weekly downloads
115,176
License
MIT
Repository
github
Last release
4 years ago

React Scroll Lock

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.
react-images-tmpspotto-searchseek-asia-style-guide@everything-registry/sub-chunk-2610@uidu/onboarding@uidu/modal-dialog@uidu/layer@voussoir/ui@vtfk/components@databyss-org/ui@app-garage/drawer@app-garage/modal@inner-desktop/react-imagesfabrictestsfabric_newnewfabricbuild@infinitebrahmanuniverse/nolb-react-sc@invyo/react-images-viewer@mattjennings/react-modalgatsby-theme-mdx-suite-basegatsby-theme-landmarks-core@joehua/dew-demofitsprint-editable-siteflwwwhariketsheth-vaultgs-react-imageshackclubindiablogshellostevengatsby-theme-consumer-site@kalamazoo/navigation@kalamazoo/layer@kalamazoo/layer-manager@kalamazoo/modal-dialog@kalamazoo/datetime-picker@kalamazoo/onboardingcredimi-frontend-componentsgc-tortilla@deplorable/react-images-viewer@huantingchen/react-imagesparlimentparatissima-react-imagesolymp-uinext-prismic-starterpubudu-laughing-pandapubudu-test-package-2r2d3testfabricreact-lightbox-with-youtubereact-dynamic-sheetreact-images-and-youtubereact-images-backdrop-fixreact-images-closereact-images-extendedreact-images-fixedreact-images-z-index-fixreact-images-zoomreact-images-zoom-loopreact-images-zoom-printsolarxuisofologyfabricscroll-lock-outsidersoury-marketplacereack-a0reack-bootstrap0reack-button0reack-checkbox0reack-clock0reack-corn0reack-dialog0reack-spinnerreack-table0reack-template-simplereact-filteredlistreact-images-maintainedreact-images-no-animationreact-images-tempreact-images-temporaryreact-images-texts-videosreact-images-lightboxreact-images-viewerreact-images-viewer-updatedreact-images-with-videoreact-images-with-youtubereack-fa0reack-fackreack-liquidityreack-login0reack-material0reack-pm0reack-select0reack-signup0react-blackboxreact-craftify-corereact-images-tsreact-images-v2react-lightbox-initialreact-trilogo-imagesrock-reack@evo/swipe-gallery@theroutingcompany/components
5.0.1

4 years ago

5.0.0

4 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago