question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cy.click() doesn't trigger click event if el to click has "tabindex=0" outside of current viewport

See original GitHub issue

Hi there,

Current behavior:

I’m using tabindex="0" across a vue app to be able to close forms with the ESC key. This feature introduces the following issue: In the tests the cy.click() calls in some cases are not triggering the actual event. Instead it seems like the click just sets the focus.

Desired behavior:

Click event should get triggered.

Test code to reproduce

I’ve tried to reproduce it with the cypress-realworld-app. You can check it out here: https://github.com/tho-masn/cypress-realworld-app/pull/1/files

To reproduce, just run the following test file: cypress/tests/ui/bankaccounts.spec.ts You will see, that the click event doesn’t get fired. There should appear a message below the “save” button saying “Submit worked”. This issue is introduced by adding tabIndex={0} to the form in BankAccountForm.tsx

There are several options to make this example work again:

  • Remove the tabIndex={0} attribute again
    • Not an option for me, as I need it to close the forms with ESC
  • Add { force: true } to the submit click call in the test.
    • Not an option for me, as I would have to add force: true to basically every click call
  • Don’t use a div with a click action handler for the submit button, but a real submit button
    • Not an option for me, as I have click handlers on divs which are not buttons
  • Reduce the height of the div below the save button to 500
    • This one is really weird. The issue only appears, if the page grows

Versions

Cypress: v4.12.1 OS: MacOS 10.15.5

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bahmutovcommented, Apr 7, 2021

Released in v6.7.0

0reactions
cypress-bot[bot]commented, Feb 23, 2021

The code for this is done in cypress-io/cypress#14710, but has yet to be released. We’ll update this issue and reference the changelog when it’s released.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress does not always executes click on element
So basically, when Cypress executes the click function, it triggers all those events but somehow my component behave the way that it is...
Read more >
How to handle Click Events in Cypress | BrowserStack
Read tutorial to perform different click events such as click, right-click, double-click, and trigger event in Cypress using examples.
Read more >
trigger | Cypress Documentation
Trigger an event on a DOM element. It is unsafe to chain further commands that rely on the subject after .trigger(). Syntax Usage...
Read more >
Angular directives for Bootstrap - AngularUI
This repository contains a set of native AngularJS directives based on Bootstrap's markup and CSS. As a result no dependency on jQuery or...
Read more >
element is being covered by another element cypress - You.com
test').click({force: true}) and cy.get('.test').trigger('mouseclick', {force: true}).click ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found