Skip to content

Commit 8c003ba

Browse files
committed
fix: support stacked mode
1 parent a24386b commit 8c003ba

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

.size-limit

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{
33
path: "dist/es2015/index.js",
44
ignore: ["react-dom", "tslib"],
5-
limit: "1.5 KB"
5+
limit: "1.9 KB"
66
}
77
]

README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,15 @@ import {RemoveScroll} from 'react-remove-scroll';
5959
See [react-remove-scroll-bar](https://github.com/theKashey/react-remove-scroll-bar) documentation for details.
6060

6161
## More than one lock
62-
This library will silence any scroll(wheel, touch) event outside of whitelisted node. To be able to use more than one lock:
63-
- disable isolation mode `<RemoveScroll noIsolation />`. Then remove scroll would handle only events, happened inside it.
64-
To use this mode you have to _cast_ some _shadow_ behind a modal, to redirect all events to your element
65-
- use [react-scroll-locky](https://github.com/theKashey/react-scroll-locky), or [react-focus-on](https://github.com/theKashey/react-focus-on), but they are lager.
62+
When stacked more is active (default) only one (last) component would be active.
63+
64+
# Performance
65+
To do the job this library setup _non_ passive event listener. Chrome dev tools would complain about it, as a
66+
performance no-op.
67+
68+
We have to use synchronous scroll/touch handler, and it may affect scrolling performance.
69+
70+
Consider using `noIsolation` mode, if you have large scrollable areas.
6671

6772
# Size
6873
1.5kb after compression (excluding tslib).

example/app.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default class App extends Component <{}, AppState> {
8484
// className={zeroRightClassName}
8585
>
8686
XXX
87-
{(<RemoveScroll enabled={!!(this.state.counter % 2)}>
87+
{(<RemoveScroll enabled={1}>
8888
<div
8989
style={{
9090
position: 'absolute',
@@ -108,6 +108,7 @@ export default class App extends Component <{}, AppState> {
108108
)}
109109
</div>
110110

111+
<RemoveScroll enabled={!!(this.state.counter % 2)}>
111112
<div
112113
style={{
113114
position: 'absolute',
@@ -116,8 +117,8 @@ export default class App extends Component <{}, AppState> {
116117
right: 0,
117118
top: '100px',
118119
//width: '100%',
119-
height: '50px',
120-
backgroundColor: 'rgba(0,0,0,0.5)'
120+
height: '150px',
121+
backgroundColor: 'rgba(0,1,0,0.5)'
121122
}}
122123
// className={fullWidthClassName}
123124
>
@@ -126,6 +127,7 @@ export default class App extends Component <{}, AppState> {
126127
XXX
127128
{fill(20, 1).map(x => <p>{x}****</p>)}
128129
</div>
130+
</RemoveScroll>
129131

130132
<div
131133
style={{

src/component.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ export class RemoveScroll extends React.Component<RemoveScrollProps> {
2525
private ref = React.createRef<HTMLDivElement>();
2626

2727
public static classNames = classNames;
28+
public static stack: Array<RemoveScroll> = [];
2829

2930
static defaultProps = {
3031
enabled: true,
3132
removeScrollBar: true,
3233
};
3334

3435
componentDidMount() {
36+
RemoveScroll.stack.push(this);
3537
this.componentDidUpdate({enabled: false})
3638
}
3739

3840
componentWillUnmount() {
41+
RemoveScroll.stack = RemoveScroll.stack.filter(inst => inst !== this);
3942
this.disable()
4043
}
4144

@@ -64,6 +67,10 @@ export class RemoveScroll extends React.Component<RemoveScrollProps> {
6467
}
6568

6669
shouldPrevent = (event: any) => {
70+
if (RemoveScroll.stack[RemoveScroll.stack.length - 1] !== this) {
71+
// not current active
72+
return;
73+
}
6774
const delta = event.deltaY || getTouchY(event);
6875
const sourceEvent = this.shouldPreventQueue.filter(
6976
(e: any) => e.name === event.type && e.delta === delta && e.target === event.target

0 commit comments

Comments
 (0)