title: React material ui: how to disable pointer capture when touching and dragging outside a Card?
body: <p>I'm using React, and have a material UI Card that toggles on and off when clicked. I am trying to <strong>1) get the card to toggle on/off correctly if the user long-presses it</strong>, and <strong>2) disable the card toggling if the user presses it and slides(drags) away, then releases</strong>. Performing these actions with a mouse has all the desired effects, and there are no problems. However, my app is used on a touch-screen monitor (without a mouse) and so I must replicate the same outcomes with touching the screen.</p>
  <p>Initially, I was using the onClick event handler to toggle the card. Long pressing with your finger (the first issue) was not properly toggling it. After a bit of research, I learned that mouse and touch events were combined into one: pointer events. So I switched <strong>onClick</strong> to <strong>onPointerUp</strong> and it worked magically.</p>
  <p>However, this is where the second issue comes in. If the user clicks the card and drags his or her finger away from it and releases, it still gets toggled (using the mouse doesn't have this same effect). I did some digging and according to MDN, pointer capture could be related:</p>
  <blockquote>
  <p>Pointer capture allows events for a particular pointer event (PointerEvent) to be re-targeted to a particular element instead of the normal (or hit test) target at a pointer's location. This can be used to ensure that an element continues to receive pointer events even if the pointer device's contact moves off the element (such as by scrolling or panning).</p>
  </blockquote>
  <p>My question is, why is the mouse click working correctly while touching doesn't? And how does one go about disabling the card getting toggled when your finger is dragged away from it?</p>
  <p><a href="https://codesandbox.io/s/elastic-dawn-qif7kq?file=/src/App.js" rel="nofollow noreferrer">Codesandbox of sample</a></p>
  <p><strong>Edit:</strong> Forgot to mention, I want the card to toggle correctly as long as the touch is released while on the card (even if it is dragged away and returns). This works fine with the mouse, but for touching, it toggles regardless of where your finger is released.</p>
  <p><strong>Edit2:</strong> Added codesandbox link.</p>
  <p>Some things of note: touch-action is set to none (CSS) and this is where the strange behavior happens, but I need to have it set that way to prevent unwanted touch registers like scrolling.</p>
  <p>I also noticed that for mouse clicks, you can select a card by clicking outside the card and dragging into it and releasing the click. I guess since the event is <strong>onPointerUp</strong> that would make sense. Although this effect is undesirable, users will only use touching in my app so it's not something I have to worry about. Regardless, I would like to understand the right way to approach this and how to achieve my desired effects.</p>