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
[Maybe by design] Button of type submit not disabled with isPending at true #6197
Comments
This does look like a bug. I think we're just setting react-spectrum/packages/@react-spectrum/button/src/Button.tsx Lines 36 to 50 in 759ac41
but instead, we could initialize isDisabled as react-spectrum/packages/@react-spectrum/button/src/Button.tsx Lines 56 to 66 in 759ac41
This may have been intentionally avoided though to prevent disabling the button while it is keyboard focused. Maybe we should instead add event handlers to the button element while in its pending state that prevent the default behavior. |
This was intentional, setting isDisabled will prevent screen reader users from accessing the button at all, so they won't know there is some long running task they are waiting for, they'll just wonder where the submit button is. It would also lose focus as @reidbarber pointed out. As @reidbarber suggested, we should probably preventDefault onClick for the pending button so that a form submit isn't called, this could happen even if the form was already submitted, resulting in a second submission. Is that what you're dealing with? Otherwise, if you're applying isPending due to something else, I would recommend not using it except when processing a direct user action on the button. |
We are currently using isPending to disable the form while processing and sending a request on form submit. |
Provide a general summary of the issue here
Not sure if this is by design, but I thought that with a Button of type submit, having the isPending prop set to true would prevent the form from being submitted but this is not the case.
🤔 Expected Behavior?
With a Button component of type submit and isPending set to true, pressing the button should not submit the form.
😯 Current Behavior
With a Button component of type submit and isPending set to true, pressing the button is triggering a form submit.
💁 Possible Solution
If this is by design, perhaps it should be explicitly explained and emphasized in the documentation.
Like this for example:
🔦 Context
No response
🖥️ Steps to Reproduce
Preview the console and spam click on the "Click me" button:
https://codesandbox.io/p/sandbox/peaceful-water-mynct4?file=%2Fsrc%2FApp.js
Version
3.32.2
What browsers are you seeing the problem on?
Chrome
If other, please specify.
No response
What operating system are you using?
Windows 10
🧢 Your Company/Team
No response
🕷 Tracking Issue
No response
The text was updated successfully, but these errors were encountered: