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

feat(react): update to React 18 #13332

Merged
merged 36 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3d4e07f
feat(react): update to React 18
tay1orjones Mar 10, 2023
3f89213
test: migrate AspectRatio test to RTL
francinelucca Mar 14, 2023
d174e9f
test(CodeSnippet): update tests to RTL
tw15egan Mar 15, 2023
9620150
test(FileUploaderButton): update tests to RTL
tw15egan Mar 15, 2023
e5720b4
test: update tests to use rtl
tay1orjones Mar 15, 2023
4548592
Merge branch 'react-18' of github.com:tay1orjones/carbon into react-18
tay1orjones Mar 15, 2023
6cb38c4
test: update fileuploader tests to use RTL
tay1orjones Mar 15, 2023
a6be384
test(FileUploader): update tests to RTL
aledavila Mar 15, 2023
6661934
Merge branch 'react-18' of github.com:tay1orjones/carbon into react-18
aledavila Mar 15, 2023
2bb3ed8
test(FileUploader): remove test utils
aledavila Mar 15, 2023
b2a66a0
feat: update File Uploader RTL
andreancardona Mar 15, 2023
6679391
test: update fileuploader tests to use RTL
tay1orjones Mar 15, 2023
421aa24
Merge branch 'react-18' of github.com:tay1orjones/carbon into react-18
tay1orjones Mar 15, 2023
f42c9e5
Merge branch 'react-18' of github.com:tay1orjones/carbon into react-18
andreancardona Mar 15, 2023
7573532
Merge branch 'react-18' of github.com:tay1orjones/carbon into react-18
tay1orjones Mar 15, 2023
ca47095
refactor: move ErrroBoundary test to RTL
francinelucca Mar 15, 2023
3255122
test: update icon test to use RTL
tay1orjones Mar 15, 2023
8a71659
Merge branch 'react-18' of github.com:tay1orjones/carbon into react-18
tay1orjones Mar 15, 2023
1f1c018
chore: @testing-library/dom is not needed and recommended to not be i…
tay1orjones Mar 16, 2023
8ba7663
fix(user-event): update deprecated keys
tay1orjones Mar 16, 2023
2fd0ac3
test: await all userEvent calls
francinelucca Mar 23, 2023
17e21d2
fix: tests
francinelucca Mar 28, 2023
a75c465
test: fix structureList & Switch react18 tests
francinelucca Apr 5, 2023
f69e51f
test: fix Copy & CopyButton react18 tests
francinelucca Apr 5, 2023
8e47a1c
test(MultiSelect): use userEvent instead of react dom utils
francinelucca Apr 6, 2023
0da93c2
test(useDisclosure): refactor test to work with react 18
francinelucca Apr 6, 2023
c45ed21
test: fix FileUploader & FileUploaderButton react18 tests
francinelucca Apr 7, 2023
cfacb83
fix(Modal): use match function to match enter & escape keys
francinelucca Apr 7, 2023
02d599f
Merge branch 'main' of github.com:carbon-design-system/carbon into re…
francinelucca Apr 7, 2023
3d39078
test(ErrorBoundary): address lint issue
francinelucca Apr 7, 2023
cf233b5
test(useDelayedState): use act from rtl instead of react-dom-utils
francinelucca Apr 7, 2023
895161d
test(Treeview): make test work in react 18
francinelucca Apr 7, 2023
356adcc
fix(Copy): remove console log
francinelucca Apr 7, 2023
35f6403
Merge branch 'main' of github.com:carbon-design-system/carbon into re…
francinelucca Apr 10, 2023
c405f66
test(IconSwitch): await userEvent calls
francinelucca Apr 10, 2023
6f396a0
Merge branch 'main' into react-18
tw15egan Apr 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions config/jest-config-carbon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"sass": "^1.51.0"
},
"devDependencies": {
"react": "^17.0.1",
"react-dom": "^17.0.1"
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
4 changes: 2 additions & 2 deletions examples/class-prefix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"dependencies": {
"@carbon/react": "^1.26.0",
"react": "^17.0.0",
"react-dom": "^17.0.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/codesandbox-with-sass-compilation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"private": true,
"dependencies": {
"@carbon/react": "^1.26.0",
"react": "^17.0.0",
"react-dom": "^17.0.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"react-scripts": "5.0.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/codesandbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"private": true,
"dependencies": {
"@carbon/react": "^1.26.0",
"react": "^17.0.0",
"react-dom": "^17.0.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"react-scripts": "5.0.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"dependencies": {
"@carbon/react": "^1.26.0",
"react": "^17.0.0",
"react-dom": "^17.0.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/id-prefix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"dependencies": {
"@carbon/react": "^1.26.0",
"react": "^17.0.0",
"react-dom": "^17.0.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/incremental-migration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"carbon-components-react": "^7.57.0",
"carbon-icons": "^7.0.7",
"next": "12.1.4",
"react": "18.0.0",
"react-dom": "18.0.0"
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"eslint": "8.12.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/light-dark-mode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"dependencies": {
"@carbon/react": "^1.26.0",
"next": "12.1.4",
"react": "18.0.0",
"react-dom": "18.0.0"
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"eslint": "8.12.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"dependencies": {
"@carbon/react": "^1.26.0",
"next": "12.1.4",
"react": "18.0.0",
"react-dom": "18.0.0"
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"eslint": "8.12.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"dependencies": {
"@carbon/react": "^1.26.0",
"react": "^17.0.0",
"react-dom": "^17.0.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.0",
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"@types/prop-types": "15.7.5",
"ast-types": "^0.14.0",
"node-sass": "^8.0.0",
"react": "~17.0.2",
"react-dom": "~17.0.2",
"react-is": "~17.0.2",
"react": "~18.2.0",
"react-dom": "~18.2.0",
"react-is": "~18.2.0",
"react-test-renderer": "~17.0.2"
},
"devDependencies": {
Expand All @@ -53,10 +53,9 @@
"@percy/cli": "^1.1.0",
"@percy/playwright": "^1.0.4",
"@playwright/test": "^1.28.0",
"@testing-library/dom": "^8.11.1",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"accessibility-checker": "^3.1.32",
"all-contributors-cli": "^6.19.0",
"cross-env": "^7.0.0",
Expand All @@ -72,8 +71,8 @@
"lint-staged": "^13.0.0",
"node-gyp": "^7.1.2",
"prettier": "^2.7.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rimraf": "^4.0.0",
"stylelint": "^14.3.0"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/carbon-components-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"postinstall": "carbon-telemetry collect --install && node scripts/postinstall.js"
},
"peerDependencies": {
"react": "^16.8.6 || ^17.0.1",
"react-dom": "^16.8.6 || ^17.0.1",
"react": "^16.8.6 || ^17.0.1 || ^18.2.0",
"react-dom": "^16.8.6 || ^17.0.1 || ^18.2.0",
"sass": "^1.33.0"
},
"dependencies": {
Expand All @@ -61,8 +61,8 @@
"babel-preset-carbon": "^0.4.0",
"browserslist-config-carbon": "^11.1.0",
"fs-extra": "^10.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rimraf": "^4.0.0",
"rollup": "^2.79.1",
"rollup-plugin-strip-banner": "^2.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/icon-build-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"memfs": "^3.4.0",
"prettier": "^2.7.1",
"prop-types": "^15.6.2",
"react": "^16.6.0",
"react-dom": "^16.6.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rimraf": "^4.0.0",
"rollup": "^2.79.1",
"rollup-plugin-strip-banner": "^2.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,32 @@
*/

import React from 'react';
import { render } from 'react-dom';
import { render } from '@testing-library/react';
import Icon from '../Icon';

describe('Icon', () => {
let mountNode;

beforeEach(() => {
mountNode = document.createElement('div');
document.body.appendChild(mountNode);
});

afterEach(() => {
mountNode.parentNode.removeChild(mountNode);
});

it('should render', () => {
expect(() => {
render(
<Icon width={16} height={16} viewBox="0 0 16 16">
<circle cx={8} cy={8} r={8} />
</Icon>,
mountNode
</Icon>
);
}).not.toThrow();
});

it('should treat focusable as a string', () => {
render(
const { container, rerender } = render(
<Icon width={16} height={16} viewBox="0 0 16 16">
<circle cx={8} cy={8} r={8} />
</Icon>,
mountNode
</Icon>
);

const getContainer = () => mountNode.querySelector('svg');
const getContainer = () => container.querySelector('svg');
expect(getContainer()).toHaveAttribute('focusable', 'false');

render(<Icon focusable />, mountNode);
rerender(<Icon focusable />);

expect(getContainer()).toHaveAttribute('focusable', 'true');
});

Expand All @@ -54,19 +42,18 @@ describe('Icon', () => {
const ref = jest.fn((node) => {
svg = node;
});
render(<Icon ref={ref} />, mountNode);
expect(svg).toEqual(mountNode.querySelector('svg'));
const { container } = render(<Icon ref={ref} />);
expect(svg).toEqual(container.querySelector('svg'));
});

it('should be focusable if an aria label and tab index is used', () => {
const getContainer = () => mountNode.querySelector('svg');
const getContainer = () => container.querySelector('svg');

// Test without a tabIndex, should not be focusable
render(
const { container, rerender } = render(
<Icon width={16} height={16} viewBox="0 0 16 16" aria-label="Mock icon">
<circle cx={8} cy={8} r={8} />
</Icon>,
mountNode
</Icon>
);

expect(getContainer()).toHaveAttribute('aria-label', 'Mock icon');
Expand All @@ -75,28 +62,26 @@ describe('Icon', () => {

// Test without aria-label and with tabIndex, should not be focusable
// because we require a label in that case
render(
rerender(
<Icon width={16} height={16} viewBox="0 0 16 16" tabIndex="0">
<circle cx={8} cy={8} r={8} />
</Icon>,
mountNode
</Icon>
);

expect(getContainer()).not.toHaveAttribute('aria-label');
getContainer().focus();
expect(document.activeElement === getContainer()).toBe(false);

// Test with aria-label and tabIndex, should be focusable
render(
rerender(
<Icon
width={16}
height={16}
viewBox="0 0 16 16"
aria-label="Mock icon"
tabIndex="0">
<circle cx={8} cy={8} r={8} />
</Icon>,
mountNode
</Icon>
);

expect(getContainer()).toHaveAttribute('aria-label', 'Mock icon');
Expand Down
3 changes: 3 additions & 0 deletions packages/react/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ module.exports = {
typescript: {
reactDocgen: 'react-docgen', // Favor docgen from prop-types instead of TS interfaces
},
reactOptions: {
legacyRootApi: false,
},
webpack(config) {
const babelLoader = config.module.rules.find((rule) => {
return rule.use.some(({ loader }) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"storybook": "start-storybook -p 3000"
},
"peerDependencies": {
"react": "^16.8.6 || ^17.0.1",
"react-dom": "^16.8.6 || ^17.0.1",
"react": "^16.8.6 || ^17.0.1 || ^18.2.0",
"react-dom": "^16.8.6 || ^17.0.1 || ^18.2.0",
"sass": "^1.33.0"
},
"dependencies": {
Expand All @@ -59,7 +59,7 @@
"lodash.omit": "^4.5.0",
"lodash.throttle": "^4.1.1",
"prop-types": "^15.7.2",
"react-is": "^17.0.2",
"react-is": "^18.2.0",
"use-resize-observer": "^6.0.0",
"wicg-inert": "^3.1.1",
"window-or-global": "^1.0.1"
Expand Down Expand Up @@ -106,8 +106,8 @@
"postcss-loader": "^7.0.0",
"process": "^0.11.10",
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"requestanimationframe": "^0.0.23",
"rimraf": "^4.0.0",
"rollup": "^2.79.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Accordion', () => {
await expect(screen.getByText('Heading A')).toHaveNoAxeViolations();

// click to open
userEvent.click(screen.getByText('Heading A'));
await userEvent.click(screen.getByText('Heading A'));

// test when open
await expect(screen.getByText('Heading A')).toHaveNoAxeViolations();
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('Accordion', () => {
);

// click to open
userEvent.click(screen.getByText('Heading A'));
await userEvent.click(screen.getByText('Heading A'));

// test when open
await expect(screen.getByText('Heading A')).toHaveNoACViolations(
Expand All @@ -105,7 +105,7 @@ describe('Accordion', () => {
</Accordion>
);

userEvent.tab();
await userEvent.tab();
await expect(document.getElementsByTagName('button')[0]).toHaveFocus();
});

Expand All @@ -126,7 +126,7 @@ describe('Accordion', () => {

// userEvent.type clicks the element passed before typing without skipClick option
// see: https://github.com/testing-library/user-event#typeelement-text-options
userEvent.type(screen.getByText('Heading A'), '{enter}', {
await userEvent.type(screen.getByText('Heading A'), '{enter}', {
skipClick: true,
});

Expand All @@ -150,7 +150,7 @@ describe('Accordion', () => {

// userEvent.type clicks the element passed before typing without skipClick option
// see: https://github.com/testing-library/user-event#typeelement-text-options
userEvent.type(screen.getByText('Heading A'), '{space}', {
await userEvent.type(screen.getByText('Heading A'), '{Space}', {
skipClick: true,
});

Expand Down