react-spectrum: Press seems to be double triggered for overlaying buttons on chrome simulated touch

πŸ› Bug Report

Given a dialog with a close button exactly overlaying the open button (not unusual for burger-menu-style navigation), clicking the open button with chrome simulated touch, triggers the close callback of the close button directly after the open callback (in ~90% of the cases?! πŸ˜“) resulting in the dialog closing immediately. (See Code Sample)

(open and close refer to stately’s useOverlayTriggerState setters)

πŸ€” Expected Behavior

Clicking the open button with simulated touch in chrome only triggers open.

😯 Current Behavior

Clicking the open button with simulated touch in chrome triggers open, then close immediately after.

πŸ’ Possible Solution

🧐

πŸ”¦ Context

We’re building a β€œDrawer” component / mobile navigation where the open and close button are in the same screen location.

It’s probably not the worst thing ever. I could not reproduce this with any form of real click or real touch input. Also Firefox simulated touch seems to work fine.

It still is kinda frustrating since chrome is our main development environment.

πŸ’» Code Sample

Here is a code sandbox showcasing the behavior.

https://codesandbox.io/s/ckmr5?file=/src/App.js

https://ckmr5.csb.app/

  • Open the sandbox in chrome
  • open devtools
  • go to any touch simulated device preview
  • press menu

🌍 Your Environment

Software Version(s)
react-aria 3.1.1
react-stately 3.0.1
Browser Chrome Version 87.0.4280.63
Operating System macOS 10.15.7 (19H15)

🧒 Your Company/Team

πŸ•· Tracking Issue (optional)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 5
  • Comments: 19 (8 by maintainers)

Most upvoted comments

as a workaround, I added a 200ms await on the first line of the onPress handler. So hacky, so bad. But nothing else I can do:

<Button
    onPress={async () => {
        await sleep(200)
        setIsVisible(false)
    }}
>
    <X size={16} weight="bold" />
</Button>

this is my hacky sleep function:

export function sleep(duration: number) {
    return new Promise(resolve => setTimeout(resolve, duration))
}