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!: remove focusTrap option #772

Merged
merged 1 commit into from
Oct 30, 2021
Merged

fix!: remove focusTrap option #772

merged 1 commit into from
Oct 30, 2021

Conversation

ph-fritsche
Copy link
Member

@ph-fritsche ph-fritsche commented Oct 30, 2021

What:

Remove focusTrap option from userEvent.tab

Why:

The focusTrap option was introduced so that userEvent.tab could be used with the focus-trap-react package. See #193

If there was an issue with this, it has been resolved.
The following test passes (no codesandbox because focus-trap-react does not work with the jsdom version used by codesandbox):

import React from 'react'
import FocusTrap from 'focus-trap-react'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'

test('focus-trap-react traps focus', () => {
    render(<div>
      <FocusTrap>
        <div>
          <button>A</button>
          <button>B</button>
        </div>
      </FocusTrap>
      <div>
        <button>C</button>
      </div>
    </div>)
  userEvent.keyboard('[Tab]')
  expect(screen.getByText('A')).toHaveFocus()
  userEvent.keyboard('[Tab]')
  expect(screen.getByText('B')).toHaveFocus()
  userEvent.keyboard('[Tab]')
  expect(screen.getByText('A')).toHaveFocus()
})

How:

Without the option and by using the implementation in #767
userEvent.tab could be boiled down to be a small convenience wrapper around userEvent.keyboard.

tab() is equal to keyboard('{Tab}')
tab({shift: true}) is equal to keyboard('{Shift>}{Tab}{/Shift}')
tab({shift: false}) is equal to keyboard('[/ShiftLeft][/ShiftRight]{Tab}')

Checklist:

  • Documentation
  • Tests
  • Ready to be merged

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 482079e:

Sandbox Source
userEvent-PR-template Configuration

@codecov
Copy link

codecov bot commented Oct 30, 2021

Codecov Report

Merging #772 (482079e) into alpha (e39177e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             alpha      #772   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           65        64    -1     
  Lines         1320      1303   -17     
  Branches       508       504    -4     
=========================================
- Hits          1320      1303   -17     
Impacted Files Coverage Δ
src/setup.ts 100.00% <ø> (ø)
src/keyboard/plugins/functional.ts 100.00% <100.00%> (ø)
src/tab.ts 100.00% <100.00%> (ø)
src/utils/focus/getTabDestination.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e39177e...482079e. Read the comment docs.

@ph-fritsche ph-fritsche added this to the userEvent v14 milestone Oct 30, 2021
@ph-fritsche ph-fritsche merged commit 5434f3f into alpha Oct 30, 2021
@ph-fritsche ph-fritsche deleted the focusTrap branch October 30, 2021 20:14
@github-actions
Copy link

🎉 This PR is included in version 14.0.0-alpha.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

ph-fritsche added a commit that referenced this pull request Nov 28, 2021
BREAKING CHANGE: The `focusTrap` option has been removed from `userEvent.tab()`.
stipsan added a commit to sanity-io/sanity that referenced this pull request Sep 14, 2022
rexxars pushed a commit to sanity-io/sanity that referenced this pull request Sep 14, 2022
stipsan added a commit to sanity-io/sanity that referenced this pull request Sep 14, 2022
stipsan added a commit to sanity-io/sanity that referenced this pull request Sep 19, 2022
stipsan added a commit to sanity-io/sanity that referenced this pull request Sep 22, 2022
stipsan added a commit to sanity-io/sanity that referenced this pull request Sep 22, 2022
stipsan added a commit to sanity-io/sanity that referenced this pull request Sep 25, 2022
stipsan added a commit to sanity-io/sanity that referenced this pull request Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant