-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Clicking nested element in disabled button invokes button's onclick handler #28788
Comments
@nils4cosee Thank you for the clear reproducible example. This is surely a bug. We're open to a pull request to fix this. This bug is in the cypress/packages/driver package within this repo. I feel like the logic may be in the cy.click logic is defined here: https://github.com/cypress-io/cypress/blob/a11y-fixes-1/packages/driver/src/cy/commands/actions/click.ts#L259 A test case would be added here to test this new behavior.: https://github.com/cypress-io/cypress/blob/a11y-fixes-1/packages/driver/cypress/e2e/commands/actions/click.cy.js |
Apparently, disabled elements on Chrome do not prevent their children from firing Maybe it is because according to the HTML spec, "actually disabled" elements can only ever be buttons, inputs, selects, textareas, options etc. ie. elements that must not have interactive content descendants. My idea would be to check if the mouse down or mouse up elements have an "actually disabled" parent, and skip the click command if they do. Will open a PR shortly. |
If mouseUp element or mouseDown element or commonAncestor element is :disabled, click event should be prevented
tests that no click events are registered when click happens on child of disabled element
If mouseUp element or mouseDown element have an "actually disabled" parent, the click event should not be registered
* fixes #28788 -- mouse.ts logic If mouseUp element or mouseDown element or commonAncestor element is :disabled, click event should be prevented * fixes #28788 -- e2e test tests that no click events are registered when click happens on child of disabled element * fixes #28788 -- mouse.ts logic If mouseUp element or mouseDown element have an "actually disabled" parent, the click event should not be registered * refactoring: minor name changes for readability * fixes #24322 --added changelog entry * Update packages/driver/src/cy/mouse.ts Co-authored-by: Bill Glesias <bglesias@gmail.com> * Update packages/driver/cypress/e2e/commands/actions/click.cy.js Co-authored-by: Bill Glesias <bglesias@gmail.com> * Update packages/driver/src/cy/mouse.ts Co-authored-by: Bill Glesias <bglesias@gmail.com> * Update packages/driver/src/cy/mouse.ts Co-authored-by: Bill Glesias <bglesias@gmail.com> * update mouse.ts -- unexpected token * docs: moved entry to 13.6.5 * Update CHANGELOG.md * Update CHANGELOG.md * Update packages/driver/cypress/e2e/commands/actions/click.cy.js Co-authored-by: Bill Glesias <bglesias@gmail.com> * Update cli/CHANGELOG.md Co-authored-by: Bill Glesias <bglesias@gmail.com> * lint: fixed 2 linting errors 565:1 error Expected indentation of 8 spaces but found 10 indent 567:7 error Expected blank line before this statement padding-line-between-statements * style: removed trailing space 567:1 error Trailing spaces not allowed no-trailing-spaces * Update CHANGELOG.md --------- Co-authored-by: Bill Glesias <bglesias@gmail.com> Co-authored-by: Jennifer Shehane <jennifer@cypress.io> Co-authored-by: Cacie Prins <cacieprins@users.noreply.github.com>
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior
When "clicking" a nested element of a disabled button, the onclick-handler of this button is run (in Chrome or Firefox, not in Electron)
Test:
Desired behavior
The behavior of
should be the same as
it only runs the onclick-handler if the button is not disabled and also waits for the button to be not disabled anymore.
Test code to reproduce
See my repo with the code https://github.com/nils4cosee/cypress-click-span-in-disabled-button
Cypress Version
13.6.1
Node version
18.15.0
Operating System
macOS 13.6
Debug Logs
is too long, according to GitHub. Please tell me if you really need it
The text was updated successfully, but these errors were encountered: