Git Product home page Git Product logo

react-scroll-locky's Introduction

๐Ÿ’€ react-scroll-locky was replaced by react-remove-scroll ๐Ÿ’€

๐Ÿ“œ๐Ÿ”’ react-scroll-locky


๐Ÿ“œ Prevents page from being scrolled. Or any other "not permitted" container.

๐Ÿ’ก Hides scrollbars, preserving page width.

๐Ÿค˜ Works on any desktop or mobile browser.

๐Ÿ“ฆ All features are hidden inside.

๐Ÿ‘ซ Stands more that one instance.

๐Ÿค” Supports nested locks

๐Ÿ”ฅ Supports nested scrollable elements.

Just wrap your content with <ScrollLocky /> and it block any iterations with the rest of a page.

This is one line solution for the problem.

All due to React-Locky it uses underneath

this could be dangerous for focus state management. Consider use more composite library - react-focus-on - to handle the every edge case.

  • focus
  • scroll
  • aria (inert)

PS

I've create react-remove-scroll - a smaller version of this library.

API

Just wrap anything with ScrollLocky, which accepts only one prop - "enabled"

There is only a few pros to configure

  • noRelative - do not apply "position:relative" on body.
  • noImportant - do not apply "!important" to any rules.
  • className - className for a internal div
  • headless - enables "no-div" mode (will pick the first DOM node-inside)
  • enabled - allows to disable Lock behavior (CSS modification and Locky), keeping it rendered.
  • isolation - allows to disable event isolation, preventing only scroll events, not everything outside target node (default behaviour). Use isolation:false if you have some "shadow" underneath modal, to catch and redirect all events.
  • gapMode=[padding|margin(default)] - gap policy, to control the way scrollLocky generate the gap instead of scrollbars. This option affects how absolutely positioned elements will work:
    • gapMode="padding" - "right:0" will be on window right (will jump on scroll removal)
    • gapMode="margin" - "right:0" will be in constant position (will not jump, but leave a gap)
import {ScrollLocky} from 'react-scroll-locky';

<Modal>
 <ScrollLocky>
   <MyContent>
     Anything!
   </MyContent>
 </ScrollLocky>
</Modal>   

Hide scrollbars only

To hide body scrollbars only (does not disable scroll on scrollable container, or body scroll on iOS) use HideBodyScroll component

import {HideBodyScroll} from 'react-scroll-locky';

<HideBodyScroll noRelative noImportant gapMode/> // body scrollbar is hidden

The order

You may have more than one active Lock on the page:

  • Only first Lock is real. Only it hides the scrollbars.
  • Only the last Lock is active. Only last-mounted Locky is working, silencing the rest of a page.
  • To have more that one active lock - consider using HideBodyScroll + react-locky directly.

Gap modes

  • "padding" - for the simple use. It will keep scroll-bar-gap for the normal elements, letting absolutely or fixed positioned elements hit the right-most window edge.
  • "margin" - for the advanced use. Will always preserve the gap, letting only the fixed positioned elements fill the while page(preffered mode)

Default Gap Mode is "margin", it would fit for almost anyone. But if you have another margin on your body (please dont), or have width:100% on the body - it would not.

Then, and only then use gapMode="padding", and dont forget to add box-sizing: border-box; to include paddings, we are going to set, to your width. (and don't send paddings on body, then).

To fill the gap with absolute positioned elements - use another exposed component.

Special component - ScrollLockyPane will help maintain the right "right" position. Alternatively - use react-scroll-locky-edge-right class, to set proper right border for a container.

import {ScrollLocky, ScrollLockyPane} from 'react-scroll-locky';

// position:absolute, left:0, right: -"gap"px
<ScrollLockyPane>
  // your modal inside
  <Modal>
     <ScrollLocky>
        <MyContent/>  
     </ScrollLocky>
  </Modal> 
</ScrollLockyPane>

ScrollLockyPane will "return" the "consumed" width to the component.

Multiple locks

  • If you need multiple locks to be active in a same time - just do it. They will work together.

Article

There is a medium article about preventing the body scroll - How to fight the scroll

More

For a good modals you also need a proper Focus Management Library. Use react-focus-lock to complete the picture.

See also

Licence

MIT

react-scroll-locky's People

Contributors

denkristoffer avatar thekashey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

livecoinwatch

react-scroll-locky's Issues

scrolling is jittery on latest iOS

When using the basic ScrollLocky component, it works as intended but the scrolling behaviour is strange. I can scroll for maybe 100px before it locks. I have to lift my finger and scroll again to make any significant scroll progress down the page.

Ignored attempt to cancel a touchmove event when isolation is false

I'm using the library with a mobile menu like this:

import { ScrollLocky } from 'react-scroll-locky';
import MotionDrawer from 'react-motion-drawer';
<MotionWrapper>
	<ScrollLocky enabled={isMobileMenuOpen} isolation={false}>
	  <MotionDrawer
	    open={isMobileMenuOpen}
	    width="100%"
	    zIndex={10}
	    className="motionDrawer"
	    onChange={handleChange}
	  >
	    // content
	  </MotionDrawer>
	</ScrollLocky>
</MotionWrapper>

The problem is that above the mobile menu I have a button which closes the menu (x sign). Therefore I need to use isolation={false} in order to enable onClick events. Everything works but I get the error in Chrome console:

[Intervention] Ignored attempt to cancel a touchmove event with cancelable=false, for example because scrolling is in progress and cannot be interrupted.
ย  | preventAll | @ | utils.js:2
-- | -- | -- | --
ย  | handleScroll | @ | handleScroll.js:51
ย  | (anonymous) | @ | index.js:47

Is there anything I can do about it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.