Skip to content
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

Form submits with disabled button #2398

Open
1 task
arome opened this issue Jan 10, 2025 · 1 comment
Open
1 task

Form submits with disabled button #2398

arome opened this issue Jan 10, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@arome
Copy link
Contributor

arome commented Jan 10, 2025

Describe the bug (current behavior)

Disabled buttons in a form still triggers the submit action on click.
Also since the buttons are not "actually" disabled, when testing with testing library, expect(submitButton).toBeDisabled() returns false even thought the button is visually disabled.

Expected Behavior

If the button is disabled and is clicked, the form should not be submitted.

Link to minimal repro

https://stackblitz.com/edit/github-vzhjqhvd?file=src%2FApp.tsx

Steps To Reproduce

  1. Click on disabled button from iTwinUI in form 1, the form will still submit.
  2. Click on disabled normal html button in form 2, the form will not submit.

Package Version

  • I'm using the latest version of iTwinUI.

Anything else?

I'm using version 3.16.0

@arome arome added the bug Something isn't working label Jan 10, 2025
@mayank99
Copy link
Contributor

This is happening because iTwinUI uses a custom, more accessible implementation of disabled buttons (#1461). The simplest solution would be to not use type="submit" when the button is disabled. You can do that manually for now, but in a future release we can handle it automatically so that the linked sandbox works as expected.

Aside: The toBeDisabled() not matching is a bug in testing-library. iTwinUI sets aria-disabled on the button, so it should match (it does so in Playwright for comparison).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants