Skip to content

Commit

Permalink
fix(): stop propagation of thumb click events
Browse files Browse the repository at this point in the history
Scrollable - stop propagation on click thumb
  • Loading branch information
ykadosh committed Aug 29, 2021
2 parents 41c5f36 + 542cadb commit 51c9a7a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const HorizontalScrollbar = () => {
const props = Movable.useMove(useMemo(() => [move(container, thumb, track)], [container]));

const handleOnClick = e => {
e.stopPropagation();
// Ignore clicks on the thumb itself
if (!thumb.current.contains(e.target)) {
const {left, width} = track.current.getBoundingClientRect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ describe('<HorizontalScrollbar/>', () => {
rewire.__Rewire__('useContext', () => ({container}));
const wrapper = shallow(<HorizontalScrollbar/>);

wrapper.find('.scrollbar-track').prop('onClick')({clientX: 0});
wrapper.find('.scrollbar-track').prop('onClick')({clientX: 0, stopPropagation: noop});
expect(container.current.scrollLeft).toEqual(0);

wrapper.find('.scrollbar-track').prop('onClick')({clientX: 50});
wrapper.find('.scrollbar-track').prop('onClick')({clientX: 50, stopPropagation: noop});
expect(container.current.scrollLeft).toEqual(100);

rewire.__ResetDependency__('useRef');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const VerticalScrollbar = () => {
const props = Movable.useMove(useMemo(() => [move(container, thumb, track)], [container]));

const handleOnClick = e => {
e.stopPropagation();
// Ignore clicks on the thumb itself
if (!thumb.current.contains(e.target)) {
const {top, height} = track.current.getBoundingClientRect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ describe('<VerticalScrollbar/>', () => {
rewire.__Rewire__('useContext', () => ({container}));
const wrapper = shallow(<VerticalScrollbar/>);

wrapper.find('.scrollbar-track').prop('onClick')({clientY: 0});
wrapper.find('.scrollbar-track').prop('onClick')({clientY: 0, stopPropagation: noop});
expect(container.current.scrollTop).toEqual(0);

wrapper.find('.scrollbar-track').prop('onClick')({clientY: 50});
wrapper.find('.scrollbar-track').prop('onClick')({clientY: 50, stopPropagation: noop});
expect(container.current.scrollTop).toEqual(100);

rewire.__ResetDependency__('useRef');
Expand Down

0 comments on commit 51c9a7a

Please sign in to comment.