You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Clicking nested element in disabled button invokes button's onclick handler #28788
it("does not invoke the onclick handler of a disabled parent button",()=>{cy.visit("index.html")cy.contains("span","Click me").click()cy.contains("Button clicked").should('not.exist')})
Desired behavior
The behavior of
cy.contains("span","Click me").click()
should be the same as
cy.contains("button","Click me").click()
it only runs the onclick-handler if the button is not disabled and also waits for the button to be not disabled anymore.
@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.
Apparently, disabled elements on Chrome do not prevent their children from firing "click" events. see this codepen.
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.
Activity
jennifer-shehane commentedon Jan 24, 2024
@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
mouse.tslogic? https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/mouse.tscy.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
TheoAnastasiadis commentedon Jan 26, 2024
Apparently, disabled elements on Chrome do not prevent their children from firing
"click"events. see this codepen.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.
fixes cypress-io#28788 -- mouse.ts logic
fixes cypress-io#28788 -- e2e test
fixes cypress-io#28788 -- mouse.ts logic
fix: Disabled elements being clickable (#28807)
cypress-bot commentedon Mar 13, 2024
Released in
13.7.0.This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v13.7.0, please open a new issue.