Skip to content

Clicking nested element in disabled button invokes button's onclick handler #28788

Closed
@nils4cosee

Description

@nils4cosee

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)

<body>
    <button disabled onclick="document.querySelector('div').innerText = 'Button clicked'">
        <span>Click me</span>
    </button>
    <div>

    </div>
</body>
</html>

Test:

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')
})

image

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.

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

Output of 


DEBUG=cypress:* npm run cypress:run -- --browser chrome --headless >debug.log 2>&1

is too long, according to GitHub. Please tell me if you really need it



### Other

_No response_

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions