Skip to content

Commit 103ceb0

Browse files
author
Marek Rozmus
committed
Add scroll blocking for specific element
1 parent 4b3c539 commit 103ceb0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/SwipeableList.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33

44
import styles from './SwipeableList.css';
55

6-
const SwipeableList = ({ children, threshold }) => {
6+
const SwipeableList = ({ children, scrollElement, threshold }) => {
77
const [blockSwipe, setBlockSwipe] = useState(false);
88

99
useEffect(() => {
@@ -16,6 +16,18 @@ const SwipeableList = ({ children, threshold }) => {
1616
};
1717
}, []);
1818

19+
useEffect(() => {
20+
if (scrollElement) {
21+
scrollElement.addEventListener('scroll', handleScroll);
22+
}
23+
24+
return () => {
25+
if (scrollElement) {
26+
scrollElement.removeEventListener('scroll', handleScroll);
27+
}
28+
};
29+
}, [scrollElement]);
30+
1931
const handleDragStart = () => setBlockSwipe(false);
2032

2133
const handleDragEnd = () => setBlockSwipe(false);
@@ -39,6 +51,7 @@ const SwipeableList = ({ children, threshold }) => {
3951

4052
SwipeableList.propTypes = {
4153
children: PropTypes.node,
54+
scrollElement: PropTypes.instanceOf(EventTarget),
4255
threshold: PropTypes.number
4356
};
4457

0 commit comments

Comments
 (0)