Skip to content

useButton/usePress should not propagate press events when isDisabled #6128

@cevr

Description

@cevr

Provide a general summary of the issue here

When a button is disabled, it still allows click events to propagate.

This is a problem when you have a pressable element nested within another pressable element (eg a card with a button in it).

This manifests for example if you disable a button when an action is loading.

🤔 Expected Behavior?

Even if the button is disabled, it still disallows click events to propagate.

😯 Current Behavior

When the button is disabled, click events are propagated.

https://stackblitz.com/edit/vitejs-vite-nyw2s2?file=src%2FApp.tsx

💁 Possible Solution

Disallow press event propagation when disabled

🔦 Context

This makes it so users accidentally fire the container element's onPress event if they try to press a disabled button - causing for a frustrating user experience.

🖥️ Steps to Reproduce

  1. Create a container element that uses useButton
  2. Create an inner element that uses useButton
  3. Disable the inner element.
  4. Watch events propagating through to the container element.

https://stackblitz.com/edit/vitejs-vite-nyw2s2?file=src%2FApp.tsx

Version

react-aria@3.32.1

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

MacOS

🧢 Your Company/Team

No response

🕷 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