• Stars
    star
    451
  • Rank 96,968 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔒 Prevent scroll on the <body />

🚨 Not Maintained

This was a great project to learn from and fulfilled the requirements it set out to. Unfortunately, I can no-longer give this project the time it needs. Consider body-scroll-lock as an alternative.

No Maintenance Intended


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

Property Description
accountForScrollbars boolean Default: true -- Whether or not to replace the scrollbar width when active.
isActive boolean Default: true -- Whether or not the lock is active.
children element Default: 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 😢

Property Description
children element ref => element

More Repositories

1

react-images

🌄 A mobile-friendly, highly customizable, carousel component for displaying media in ReactJS
JavaScript
2,348
star
2

react-toast-notifications

🍞 A toast notification system for react
JavaScript
2,172
star
3

react-focus-marshal

👮🏻 Traps focus within a DOM node
JavaScript
82
star
4

react-blink

👁 React replacement for the <blink> element
JavaScript
70
star
5

react-radios

🔘 Proper handling of HTML radios in react
JavaScript
60
star
6

react-height-transition

📏 Animate height when children mount/unmount
JavaScript
57
star
7

jade-field-mixins

A collection of Jade mixins for defining form fields. The style and structure follow Bootstrap's form definition. Initially crafted for recreating dashboards using KeystoneJS
CSS
38
star
8

react-scroll-captor

📜 Restrict scroll events to the immediate child
JavaScript
27
star
9

interpolate-range

💯 Super simple numeric range interpolation
JavaScript
15
star
10

react-icons

Simple component for icons in your React app
JavaScript
14
star
11

react-deprecate

⚠️ Rename props with deprecation warning
JavaScript
13
star
12

react-select-simple-value

A simple value wrapper for react-select
JavaScript
12
star
13

react-node-resolver

🔍 Resolve the DOM node of any react component
JavaScript
12
star
14

react-prop-toggle

🕹 Influence nodes outside your app's render tree
JavaScript
7
star
15

react-view-transition

🎟 Animate views as they mount/unmout
JavaScript
6
star
16

react-pseudo-state

🎛 Stateful pseudo-classes in React
JavaScript
5
star
17

less-entypo-icons

A single LESS file for including entypo icons
CSS
4
star
18

react-focuslock

Restrict focus scope to a single element, typically a modal dialog
JavaScript
3
star
19

asser-ts

Assertion functions for TS
TypeScript
3
star
20

adjustable

Adjustable helper utilities for CSS-in-JS
JavaScript
2
star
21

simple-grid

A simple, responsive grid
CSS
1
star
22

react-sronly

🗣 Provide accessible text to Screen Readers
JavaScript
1
star
23

swipe

experiment with touch events
JavaScript
1
star