Skip to content

Commit

Permalink
feat(react): update to React 18 (#13332)
Browse files Browse the repository at this point in the history
* feat(react): update to React 18

* test: migrate AspectRatio test to RTL

* test(CodeSnippet): update tests to RTL

* test(FileUploaderButton): update tests to RTL

* test: update tests to use rtl

* test: update fileuploader tests to use RTL

* test(FileUploader): update tests to RTL

* test(FileUploader): remove test utils

* feat: update File Uploader RTL

* test: update fileuploader tests to use RTL

* refactor: move ErrroBoundary test to RTL

* test: update icon test to use RTL

* chore: @testing-library/dom is not needed and recommended to not be installed alongside framework packages

* fix(user-event): update deprecated keys

* test: await all userEvent calls

* fix: tests

* test: fix structureList & Switch react18 tests

* test: fix Copy & CopyButton react18 tests

* test(MultiSelect): use userEvent instead of react dom utils

* test(useDisclosure): refactor test to work with react 18

* test: fix FileUploader & FileUploaderButton react18 tests

* fix(Modal): use match function to match enter & escape keys

* test(ErrorBoundary): address lint issue

* test(useDelayedState): use act from rtl instead of react-dom-utils

* test(Treeview): make test work in react 18

* fix(Copy): remove console log

* test(IconSwitch): await userEvent calls

---------

Co-authored-by: Francine Lucca <francinelucca@hotmail.com>
Co-authored-by: TJ Egan <tw15egan@gmail.com>
Co-authored-by: Alessandra Davila <adavila91@gmail.com>
Co-authored-by: Andrea N. Cardona <cardona.n.andrea@gmail.com>
  • Loading branch information
5 people committed Apr 11, 2023
1 parent 51bc361 commit 7b9a05b
Show file tree
Hide file tree
Showing 127 changed files with 1,022 additions and 1,065 deletions.
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

0 comments on commit 7b9a05b

Please sign in to comment.