Skip to content

Conversation

@just-be-dev
Copy link
Contributor

We discussed this in chat a few days ago. Even though the accessibility of disabled buttons was improved in #1292, it's typically accepted that form submit buttons shouldn't be disabled, but should just trigger validation instead. This PR takes that action.

Changes

  • Submit buttons in forms are no longer disabled
  • Forms now take loading as a prop which is used to prevent double submits
  • submitDisabled is updated to take a string such that if we do need to disable a submit button, we can ensure a reason is provided

@vercel
Copy link

vercel bot commented Nov 11, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
console-ui-storybook ✅ Ready (Inspect) Visit Preview Nov 15, 2022 at 9:48PM (UTC)

<Button
type="submit"
size="sm"
disabled={!!submitDisabled}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The button is still clickable while the request is going through, which means you can submit multiple times. Rather than changing Button internally so that loading also causes it to be disabled, I think I prefer keeping the disabled prop as the only one that can actually disable the button and changing the call to be something like this:

Suggested change
disabled={!!submitDisabled}
disabled={!!submitDisabled || loading || isSubmitting}

Copy link
Contributor Author

@just-be-dev just-be-dev Nov 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that, I'd left out some logic. We have to supply loading with the proper state in order to provide the visual indication that it is indeed loading. Given we need to supply that state and it seems like invalid behavior to have a button both loading and clickable then it seems reasonable to expect the loading prop would disable the button.

If we don't then we must always pass the loading state twice in the same component usage. Not doing so would result in a bug.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's true. We'd never want a button clickable while loading. Fine with me.

@just-be-dev just-be-dev merged commit 06298aa into main Nov 16, 2022
@just-be-dev just-be-dev deleted the better-disabled-behaviors branch November 16, 2022 00:20
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.

3 participants