Skip to content

fix(button): blur button to remove pressed state after modal opens (#… #8520

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Ch1C0rj
Copy link

@Ch1C0rj Ch1C0rj commented Jul 10, 2025

…8339)

This PR fixes issue #8339 where a button remains in a data-pressed="true" state after opening a modal using DialogTrigger.

The fix ensures that the button blurs on click, removing the pressed state immediately after interaction.

Behavior Before
Clicking a button that opens a modal caused it to remain visually "pressed"

data-pressed="true" would persist even while the modal was open

This created a distracting UI effect, especially with outlined/animated buttons

Behavior After
The button now calls .blur() on click

The data-pressed attribute is removed as expected

The visual feedback resets properly after modal opens

Fix Location
The fix was added directly to the JSX inside packages/@react-spectrum/button/src/Button.tsx by adding an onClick handler:

onClick={(e) => {
e.currentTarget.blur();
props.onClick?.(e);
}}

Existing button behavior and modal triggering remain unaffected

No breaking changes introduced

@snowystinger
Copy link
Member

Thanks for the interest. Please have a read through this comment #8339 (comment) and please add some comments as to why your solution differs from the proposed solution. We'd like to know what the reasoning was.

In addition, it looks like the yarn lock was updated, this should not be the case, please revert that file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants