Skip to content

[RAC] Button's onPress behaves differently in test and dev environments #8082

@annaet

Description

@annaet

Provide a general summary of the issue here

In the browser the React ARIA Button component swallows pointerdown events, meaning that other components listening on that event do not trigger.

But in a test environment clicking the Button via userEvent.click it does not swallow the event leading to tests erroneously passing.

I have created a minimal repo demonstrating this issue: https://github.com/annaet/react-aria-button-bug-demo

🤔 Expected Behavior?

Behaviour should be consistent across browser and tests.

😯 Current Behavior

Events are swallowed by Button on browser but not during tests.

💁 Possible Solution

Ideally Button would not swallow these events so that event listeners continue to work as expected.

🔦 Context

No response

🖥️ Steps to Reproduce

Clone this demo repo: https://github.com/annaet/react-aria-button-bug-demo

Run the app using npm run dev to show the browser behaviour. This shows two Menu elements that listen for pointerdown events. On an external pointerdown the menu should close.

You can open both menus at the same time, as the second button click swallows the pointerdown event meaning the first menu does not close.

The expected behaviour is in the Menu.test.tsx file, where when the second menu is clicked the first is closed.

This shows the behaviour is different between a test and development environment.

Version

"react-aria-components": "1.7.1"

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

OSX

🧢 Your Company/Team

Hudl

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions