Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: how to preventDefault in touchmove #25326

Closed
this-spring opened this issue Sep 25, 2022 · 5 comments
Closed

Bug: how to preventDefault in touchmove #25326

this-spring opened this issue Sep 25, 2022 · 5 comments
Labels
Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@this-spring
Copy link

React version:
17.0.2

Steps To Reproduce

I want the parent element to not scroll when the child element is scrolled

jsx

const App = () => {
        const styleObj = {
             height: "200vh",
             "background-image": "linear-gradient(rgb(255, 255, 255), rgb(170, 0, 0))"
        }
        function touchMove(event) {
            event.nativeEvent.preventDefault();
        }
        return (
          <div id="parent" style={ styleObj }>
             <div id="child" onTouchMove={touchMove} className="r">
             </div>
          </div>
      );
}

css:

.r {
  position: fixed;
  top: 200px;
  left: 0;
  z-index: 10;
  width: 100%;
  height: 300px;
  background-color: black;
}

When I scroll the child in mobile mode, the outer layer will follow.

Link to code example:
App.js
image

App.css
image

The current behavior

the parent scroll when child is touchmove.

The expected behavior

the parent not scroll when child is touchmove.

I saw this issues(https://github.com/facebook/react/issues/19651), I have two questions:

  1. I'm not sure if react 18 fixed it?
  2. How do I deal with this case?
@this-spring this-spring added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Sep 25, 2022
@factscub
Copy link

i want to work on this issue. please assign this to me.

@this-spring
Copy link
Author

so, it is a bug?
How do I deal with this case?

@makc
Copy link

makc commented Dec 2, 2022

@this-spring not a bug, but "by design" as per #19651
unfortunately they dont seem to care about preventDefault-s not working
so the work-around is to not use react's onXxx and instead do addEventListener with { passive: false } as per #20999

@this-spring
Copy link
Author

okk thanks

Copy link

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

3 participants