Skip to content
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

fix: Off by one error in next/previous tab #15

Merged
merged 3 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@
"autoFix": true
},
],
"editor.codeActionsOnSave": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ESLint plugin insisted on this change (added every time I removed it).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, I will keep it then

"source.fixAll.eslint": true
},
}
11 changes: 11 additions & 0 deletions cypress/integration/spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference types="cypress"/>
/* global cy */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint-staged forced me to add this.


// const { _ } = Cypress

Expand Down Expand Up @@ -93,6 +94,16 @@ describe('form test', () => {
cy.get('body').should(beFocused)
})

it('moves focus back to the first element when the last element is focused', () => {
cy.get('a:last').tab()
cy.get('a:first').should(beFocused)
})

it('moves focus back to the first element when the last element is focused', () => {
cy.get('a:first').tab({ shift: true })
cy.get('a:last').should(beFocused)
})

describe('events', () => {
beforeEach(() => {

Expand Down
17 changes: 5 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Cypress, cy */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint-staged forced me to add this

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure you are using local install of eslint? the cypress plugin should have these globals set

const tabSequence = require('ally.js/query/tabsequence')

const { _, Promise } = Cypress
Expand Down Expand Up @@ -75,22 +76,14 @@ const performTab = (el, options) => {

const nextItemFromIndex = (i, seq, reverse) => {
if (reverse) {
if (i === 0 || i === -1) {
i = seq.length
}
} else {
if (i === seq.length) {
i = 0
}
const nextIndex = i <= 0 ? seq.length - 1 : i - 1

return seq[nextIndex]
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint rules prevented an else here

// }

if (reverse) {
return seq[i - 1]
}
const nextIndex = i === seq.length - 1 ? 0 : i + 1

return seq[i + 1]
return seq[nextIndex]
}

const tabKeyEventPartial = {
Expand Down