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

add React 18 compatibility #1326

Merged
merged 17 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Mimic browser select on focus when navigating via `Tab` ([#1272](https://github.com/tailwindlabs/headlessui/pull/1272))
- Ensure that there is always an active option in the `Combobox` ([#1279](https://github.com/tailwindlabs/headlessui/pull/1279), [#1281](https://github.com/tailwindlabs/headlessui/pull/1281))
- Allow `Enter` for form submit in `RadioGroup`, `Switch` and `Combobox` improvements ([#1285](https://github.com/tailwindlabs/headlessui/pull/1285))
- add React 18 compatibility ([#1326](https://github.com/tailwindlabs/headlessui/pull/1326))

### Added

Expand Down
6 changes: 4 additions & 2 deletions jest/create-jest-config.cjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module.exports = function createJestConfig(root, options) {
let { setupFilesAfterEnv = [], transform = {}, ...rest } = options
return Object.assign(
{
rootDir: root,
setupFilesAfterEnv: ['<rootDir>../../jest/custom-matchers.ts'],
setupFilesAfterEnv: ['<rootDir>../../jest/custom-matchers.ts', ...setupFilesAfterEnv],
transform: {
'^.+\\.(t|j)sx?$': '@swc/jest',
...transform,
},
},
options
rest
)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"devDependencies": {
"@swc/core": "^1.2.131",
"@swc/jest": "^0.2.17",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/jest-dom": "^5.16.4",
"@types/node": "^14.14.22",
"esbuild": "^0.14.11",
"fast-glob": "^3.2.11",
Expand Down
5 changes: 4 additions & 1 deletion packages/@headlessui-react/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
let create = require('../../jest/create-jest-config.cjs')
module.exports = create(__dirname, { displayName: 'React' })
module.exports = create(__dirname, {
displayName: 'React',
setupFilesAfterEnv: ['./jest.setup.js'],
})
1 change: 1 addition & 0 deletions packages/@headlessui-react/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
globalThis.IS_REACT_ACT_ENVIRONMENT = true
10 changes: 5 additions & 5 deletions packages/@headlessui-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
"react-dom": "^16 || ^17 || ^18"
},
"devDependencies": {
"@testing-library/react": "^11.2.3",
"@types/react": "16.14.21",
"@types/react-dom": "^16.9.0",
"@testing-library/react": "^13.0.0",
"@types/react": "^17.0.43",
"@types/react-dom": "^17.0.14",
"esbuild": "^0.11.18",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"snapshot-diff": "^0.8.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.Enter)
Expand Down Expand Up @@ -915,7 +915,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Try to focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Try to open the combobox
await press(Keys.Enter)
Expand Down Expand Up @@ -951,7 +951,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.Enter)
Expand Down Expand Up @@ -1000,7 +1000,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleHidden })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.Enter)
Expand Down Expand Up @@ -1073,7 +1073,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.Enter)
Expand Down Expand Up @@ -1114,7 +1114,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.Enter)
Expand Down Expand Up @@ -1153,7 +1153,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.Space)
Expand Down Expand Up @@ -1200,7 +1200,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Try to open the combobox
await press(Keys.Space)
Expand Down Expand Up @@ -1238,7 +1238,7 @@ describe('Keyboard interactions', () => {
})

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.Space)
Expand Down Expand Up @@ -1278,7 +1278,7 @@ describe('Keyboard interactions', () => {
})

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.Space)
Expand Down Expand Up @@ -1319,7 +1319,7 @@ describe('Keyboard interactions', () => {
})

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.Space)
Expand Down Expand Up @@ -1358,7 +1358,7 @@ describe('Keyboard interactions', () => {
assertComboboxButtonLinkedWithCombobox()

// Re-focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())
assertActiveElement(getComboboxButton())

// Close combobox
Expand Down Expand Up @@ -1397,7 +1397,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.ArrowDown)
Expand Down Expand Up @@ -1443,7 +1443,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Try to open the combobox
await press(Keys.ArrowDown)
Expand Down Expand Up @@ -1479,7 +1479,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.ArrowDown)
Expand Down Expand Up @@ -1517,7 +1517,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.ArrowDown)
Expand Down Expand Up @@ -1552,7 +1552,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.ArrowUp)
Expand Down Expand Up @@ -1598,7 +1598,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Try to open the combobox
await press(Keys.ArrowUp)
Expand Down Expand Up @@ -1634,7 +1634,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.ArrowUp)
Expand Down Expand Up @@ -1672,7 +1672,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.ArrowUp)
Expand Down Expand Up @@ -1709,7 +1709,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the button
getComboboxButton()?.focus()
await focus(getComboboxButton())

// Open combobox
await press(Keys.ArrowUp)
Expand Down Expand Up @@ -1899,7 +1899,7 @@ describe('Keyboard interactions', () => {
render(<Example />)

// Focus the input field
getComboboxInput()?.focus()
await focus(getComboboxInput())
assertActiveElement(getComboboxInput())

// Press enter (which should submit the form)
Expand Down Expand Up @@ -2212,7 +2212,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the input
getComboboxInput()?.focus()
await focus(getComboboxInput())

// Open combobox
await press(Keys.ArrowDown)
Expand Down Expand Up @@ -2258,7 +2258,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the input
getComboboxInput()?.focus()
await focus(getComboboxInput())

// Try to open the combobox
await press(Keys.ArrowDown)
Expand Down Expand Up @@ -2294,7 +2294,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the input
getComboboxInput()?.focus()
await focus(getComboboxInput())

// Open combobox
await press(Keys.ArrowDown)
Expand Down Expand Up @@ -2332,7 +2332,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the input
getComboboxInput()?.focus()
await focus(getComboboxInput())

// Open combobox
await press(Keys.ArrowDown)
Expand Down Expand Up @@ -2527,7 +2527,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the input
getComboboxInput()?.focus()
await focus(getComboboxInput())

// Open combobox
await press(Keys.ArrowUp)
Expand Down Expand Up @@ -2573,7 +2573,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the input
getComboboxInput()?.focus()
await focus(getComboboxInput())

// Try to open the combobox
await press(Keys.ArrowUp)
Expand Down Expand Up @@ -2609,7 +2609,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the input
getComboboxInput()?.focus()
await focus(getComboboxInput())

// Open combobox
await press(Keys.ArrowUp)
Expand Down Expand Up @@ -2647,7 +2647,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the input
getComboboxInput()?.focus()
await focus(getComboboxInput())

// Open combobox
await press(Keys.ArrowUp)
Expand Down Expand Up @@ -2684,7 +2684,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the input
getComboboxInput()?.focus()
await focus(getComboboxInput())

// Open combobox
await press(Keys.ArrowUp)
Expand Down Expand Up @@ -2766,7 +2766,7 @@ describe('Keyboard interactions', () => {
assertComboboxList({ state: ComboboxState.InvisibleUnmounted })

// Focus the input
getComboboxInput()?.focus()
await focus(getComboboxInput())

// Open combobox
await press(Keys.ArrowUp)
Expand Down Expand Up @@ -3099,7 +3099,7 @@ describe('Keyboard interactions', () => {
)

// Focus the input
getComboboxInput()?.focus()
await focus(getComboboxInput())

// Open combobox
await press(Keys.ArrowUp)
Expand Down Expand Up @@ -3243,7 +3243,7 @@ describe('Keyboard interactions', () => {
)

// Focus the input
getComboboxInput()?.focus()
await focus(getComboboxInput())

// Open combobox
await press(Keys.ArrowUp)
Expand Down
Loading