-
Notifications
You must be signed in to change notification settings - Fork 3.3k
cy.click() doesn't trigger click event if el to click has "tabindex=0" outside of current viewport #8279
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
Comments
I can recreate this with the branch provided. You can see that during the click - it's highlighting the 'Bank Account' navigation on the left, as if it's focusing there for some reason. It'd be great to have a simpler example. I've tried to recreate outside of the RWA and haven't been successful. Doesn't reproduce <html>
<body>
<div>
<a tabindex="0">Link 1</a>
<div tabindex="0"></div>
</div>
<form tabindex="0">
<input/>
<div id='save'>Save</div>
<div id='success'></div>
</form>
<script>
const saveBtn = document.getElementById('save')
const successMsg = document.getElementById('success')
saveBtn.addEventListener('click', (e) => {
successMsg.innerHTML = "Success!"
})
</script>
</body>
</html> it('test', () => {
cy.visit('index.html')
cy.get('#save').click()
cy.get('#success').should('contain', 'Success')
}) |
The issue is only happening, if the clicked element is out of view. I've added a <html>
<body>
<div>
<a>Link 1</a>
<div></div>
</div>
<form tabindex="0">
<input/>
<div style="height: 2000px"></div>
<div id='save'>Save</div>
<div id='success'></div>
</form>
<script>
const saveBtn = document.getElementById('save')
const successMsg = document.getElementById('success')
saveBtn.addEventListener('click', (e) => {
successMsg.innerHTML = "Success!"
})
</script>
</body>
</html> |
Perfect! This issue does not exist in Cypress 3.4.1, so is a regression that was introduced in 3.5.0. Repro
<html>
<body>
<!-- The test passes is you remove tabindex here -->
<form tabindex="0">
<div style="height: 2000px"></div>
<div id="save">Save</div>
<div id="success"></div>
</form>
<script>
const saveBtn = document.getElementById('save')
const successMsg = document.getElementById('success')
saveBtn.addEventListener('click', (e) => {
successMsg.innerHTML = "Success!"
})
</script>
</body>
</html>
it('test', () => {
cy.visit('index.html')
cy.get('#save').click()
cy.get('#success').should('contain', 'Success')
}) |
Interesting note. This works fine in Firefox. |
This happens because of the code below: cypress/packages/driver/src/cy/mouse.js Lines 527 to 559 in 133c970
I couldn't verify whether it's the problem of Cypress or Chrome. |
cypress/packages/driver/src/cy/mouse.js Lines 453 to 484 in 133c970
if the code on line 482 is changed to and then those options are passed through in focused.js
That scroll is stopped and @jennifer-shehane repro is fixed |
The code for this is done in cypress-io/cypress#14710, but has yet to be released. |
Released in v6.7.0 |
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 thecy.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 inBankAccountForm.tsx
There are several options to make this example work again:
tabIndex={0}
attribute again{ force: true }
to the submit click call in the test.force: true
to basically every click calldiv
with a click action handler for the submit button, but a real submit button500
Versions
Cypress: v4.12.1
OS: MacOS 10.15.5
The text was updated successfully, but these errors were encountered: