@transferwise/components 0.0.0-experimental-7512130 → 0.0.0-experimental-73858ea

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/build/index.esm.js +187 -258
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +186 -257
  4. package/build/index.js.map +1 -1
  5. package/build/types/common/focusBoundary/FocusBoundary.d.ts +2 -2
  6. package/build/types/common/focusBoundary/FocusBoundary.d.ts.map +1 -1
  7. package/build/types/snackbar/Snackbar.d.ts.map +1 -1
  8. package/build/types/upload/steps/completeStep/completeStep.d.ts.map +1 -1
  9. package/build/types/upload/steps/processingStep/processingStep.d.ts.map +1 -1
  10. package/package.json +2 -1
  11. package/src/common/bottomSheet/__snapshots__/BottomSheet.spec.tsx.snap +8 -1
  12. package/src/common/focusBoundary/FocusBoundary.tsx +9 -32
  13. package/src/snackbar/Snackbar.js +1 -6
  14. package/src/snackbar/Snackbar.spec.js +3 -1
  15. package/src/snackbar/__snapshots__/Snackbar.spec.js.snap +5 -0
  16. package/src/upload/Upload.js +1 -1
  17. package/src/upload/steps/completeStep/completeStep.js +4 -1
  18. package/src/upload/steps/processingStep/processingStep.js +1 -0
  19. package/src/uploadInput/uploadItem/UploadItem.tsx +1 -1
  20. package/build/types/common/focusBoundary/utils/getFocusableElements.d.ts +0 -2
  21. package/build/types/common/focusBoundary/utils/getFocusableElements.d.ts.map +0 -1
  22. package/build/types/common/focusBoundary/utils/index.d.ts +0 -3
  23. package/build/types/common/focusBoundary/utils/index.d.ts.map +0 -1
  24. package/build/types/common/focusBoundary/utils/resetFocus.d.ts +0 -2
  25. package/build/types/common/focusBoundary/utils/resetFocus.d.ts.map +0 -1
  26. package/src/common/focusBoundary/FocusBoundary.spec.tsx +0 -66
  27. package/src/common/focusBoundary/__snapshots__/FocusBoundary.spec.tsx.snap +0 -16
  28. package/src/common/focusBoundary/utils/getFocusableElements.js +0 -25
  29. package/src/common/focusBoundary/utils/getFocusableElements.spec.js +0 -51
  30. package/src/common/focusBoundary/utils/index.js +0 -2
  31. package/src/common/focusBoundary/utils/resetFocus.js +0 -23
  32. package/src/common/focusBoundary/utils/resetFocus.spec.js +0 -103
@@ -1,6 +1,6 @@
1
- import { ReactNode } from 'react';
1
+ /// <reference types="react" />
2
2
  type FocusBoundaryProps = {
3
- children: ReactNode;
3
+ children: React.ReactNode;
4
4
  };
5
5
  declare const FocusBoundary: ({ children }: FocusBoundaryProps) => import("react").JSX.Element;
6
6
  export default FocusBoundary;
@@ -1 +1 @@
1
- {"version":3,"file":"FocusBoundary.d.ts","sourceRoot":"","sources":["../../../../src/common/focusBoundary/FocusBoundary.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA+B,MAAM,OAAO,CAAC;AAS/D,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF,QAAA,MAAM,aAAa,iBAAkB,kBAAkB,gCA6BtD,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"FocusBoundary.d.ts","sourceRoot":"","sources":["../../../../src/common/focusBoundary/FocusBoundary.tsx"],"names":[],"mappings":";AAGA,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,QAAA,MAAM,aAAa,iBAAkB,kBAAkB,gCAatD,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Snackbar.d.ts","sourceRoot":"","sources":["../../../src/snackbar/Snackbar.js"],"names":[],"mappings":"AAUA,0CAA2C;AAE3C;IAIE,cAMC;IATD,yCAAyC;IACzC,SADW,UAAU,eAAe,CAAC,CACf;IAIpB;;;MAGC;IAGH,6BAGC;IAED,+DAaC;IAED,4BAME;IAHA,oCAEW;IAGb,6CAsBC;IAVO,8CAG2B;IASnC,sCAiCC;CACF"}
1
+ {"version":3,"file":"Snackbar.d.ts","sourceRoot":"","sources":["../../../src/snackbar/Snackbar.js"],"names":[],"mappings":"AAUA,0CAA2C;AAE3C;IAIE,cAMC;IATD,yCAAyC;IACzC,SADW,UAAU,eAAe,CAAC,CACf;IAIpB;;;MAGC;IAGH,6BAGC;IAED,+DAaC;IAED,4BAME;IAHA,oCAEW;IAGb,6CAsBC;IAVO,8CAG2B;IASnC,sCA4BC;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"completeStep.d.ts","sourceRoot":"","sources":["../../../../../src/upload/steps/completeStep/completeStep.js"],"names":[],"mappings":";AAYA,uEAiEC"}
1
+ {"version":3,"file":"completeStep.d.ts","sourceRoot":"","sources":["../../../../../src/upload/steps/completeStep/completeStep.js"],"names":[],"mappings":";AAYA,uEAoEC"}
@@ -1 +1 @@
1
- {"version":3,"file":"processingStep.d.ts","sourceRoot":"","sources":["../../../../../src/upload/steps/processingStep/processingStep.js"],"names":[],"mappings":";AASA,yEAiDC"}
1
+ {"version":3,"file":"processingStep.d.ts","sourceRoot":"","sources":["../../../../../src/upload/steps/processingStep/processingStep.js"],"names":[],"mappings":";AASA,yEAkDC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "0.0.0-experimental-7512130",
3
+ "version": "0.0.0-experimental-73858ea",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -103,6 +103,7 @@
103
103
  "@headlessui/react": "^1.7.17",
104
104
  "@popperjs/core": "^2.6.0",
105
105
  "@radix-ui/react-id": "^1.0.0",
106
+ "@react-aria/focus": "^3.14.2",
106
107
  "@react-aria/overlays": "^3.17.0",
107
108
  "@react-spring/web": "~9.6.1",
108
109
  "@transferwise/formatting": "^2.1.0",
@@ -7,9 +7,12 @@ exports[`BottomSheet renders content when open 1`] = `
7
7
  class="np-theme-light"
8
8
  >
9
9
  <div
10
- class="np-focus-boundary outline-none"
11
10
  tabindex="-1"
12
11
  >
12
+ <span
13
+ data-focus-scope-start="true"
14
+ hidden=""
15
+ />
13
16
  <div
14
17
  class="dimmer"
15
18
  role="presentation"
@@ -63,6 +66,10 @@ exports[`BottomSheet renders content when open 1`] = `
63
66
  </div>
64
67
  </div>
65
68
  </div>
69
+ <span
70
+ data-focus-scope-end="true"
71
+ hidden=""
72
+ />
66
73
  </div>
67
74
  </div>
68
75
  </body>
@@ -1,44 +1,21 @@
1
- import { isKey, isUndefined } from '@transferwise/neptune-validation';
2
- import { ReactNode, useEffect, useRef, useState } from 'react';
3
-
4
- import { useConditionalListener } from '../hooks';
5
- import { Key } from '../key';
6
-
7
- import { getFocusableElements, resetFocus } from './utils';
8
-
9
- const { TAB } = Key;
1
+ import { FocusScope } from '@react-aria/focus';
2
+ import { useEffect, useRef } from 'react';
10
3
 
11
4
  type FocusBoundaryProps = {
12
- children: ReactNode;
5
+ children: React.ReactNode;
13
6
  };
14
7
 
15
8
  const FocusBoundary = ({ children }: FocusBoundaryProps) => {
16
- const boundaryReference = useRef<HTMLDivElement | null>(null);
17
- const parent = isUndefined(document) ? undefined : document;
18
- const [focusableEls, setFocusableEls] = useState({});
19
-
9
+ const wrapperReference = useRef<HTMLDivElement>(null);
20
10
  useEffect(() => {
21
- if (boundaryReference?.current) {
22
- boundaryReference.current.focus({ preventScroll: true });
23
- setFocusableEls(getFocusableElements(boundaryReference.current));
24
- }
11
+ wrapperReference.current?.focus({ preventScroll: true });
25
12
  }, []);
26
13
 
27
- // If event type is Tab the resetFocus will force the focus to either the first focusable or last in boundaryRef .
28
- useConditionalListener({
29
- eventType: 'keydown',
30
- callback: (event) => {
31
- if (isKey({ keyType: TAB, event })) {
32
- resetFocus({ event, focusableEls });
33
- }
34
- },
35
- attachListener: true,
36
- parent,
37
- });
38
-
39
14
  return (
40
- <div ref={boundaryReference} tabIndex={-1} className="np-focus-boundary outline-none">
41
- {children}
15
+ <div ref={wrapperReference} tabIndex={-1}>
16
+ <FocusScope contain restoreFocus>
17
+ {children}
18
+ </FocusScope>
42
19
  </div>
43
20
  );
44
21
  };
@@ -91,12 +91,7 @@ export class Snackbar extends Component {
91
91
  }}
92
92
  unmountOnExit
93
93
  >
94
- <Body
95
- ref={this.bodyRef}
96
- as="span"
97
- className={`snackbar__text snackbar__text--${theme}`}
98
- aria-live="polite"
99
- >
94
+ <Body ref={this.bodyRef} as="span" className={`snackbar__text snackbar__text--${theme}`}>
100
95
  {text}
101
96
  {action ? (
102
97
  <ActionButton className="snackbar__text__action" onClick={action.onClick}>
@@ -71,6 +71,8 @@ describe('Snackbar', () => {
71
71
  const snackbarWithNode = () => componentWithNode.find(Snackbar);
72
72
  componentWithNode.find('.button-trigger').simulate('click');
73
73
  expect(snackbarWithNode().text()).toContain('test');
74
+
75
+ expect(snackbarWithNode().html()).toMatchSnapshot();
74
76
  });
75
77
 
76
78
  it('displays a single snack for the given duration with the given text', async () => {
@@ -105,6 +107,6 @@ describe('Snackbar', () => {
105
107
  );
106
108
  const snackbarWithNode = () => componentWithNode.find(Snackbar);
107
109
  componentWithNode.find('.button-trigger').simulate('click');
108
- expect(snackbarWithNode().prop('theme')).toBe('dark');
110
+ expect(snackbarWithNode().html()).toMatchSnapshot();
109
111
  });
110
112
  });
@@ -0,0 +1,5 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Snackbar accepts element as text 1`] = `"<div class=\\"snackbar\\"><span class=\\"np-text-body-default snackbar__text snackbar__text--light snackbar__text-container-enter snackbar__text-container-enter-active\\"><span>test</span></span></div>"`;
4
+
5
+ exports[`Snackbar adjusts the theme if passed 1`] = `"<div class=\\"snackbar\\"><span class=\\"np-text-body-default snackbar__text snackbar__text--dark snackbar__text-container-enter snackbar__text-container-enter-active\\"><span>test</span></span></div>"`;
@@ -344,7 +344,7 @@ class Upload extends Component {
344
344
  />
345
345
  )}
346
346
  {!isProcessing && (
347
- <div className="droppable-dropping-card droppable-card">
347
+ <div className="droppable-dropping-card droppable-card" aria-live="polite">
348
348
  <div className="droppable-card-content">
349
349
  <div className="circle circle-sm text-primary">
350
350
  <PlusIcon size="16" />
@@ -26,7 +26,10 @@ const CompleteStep = (props) => {
26
26
  return (
27
27
  <div className="droppable-complete-card droppable-card" aria-hidden={!isComplete}>
28
28
  <div className="droppable-card-content">
29
- <div className="droppable-card-content d-flex flex-column align-items-center">
29
+ <div
30
+ className="droppable-card-content d-flex flex-column align-items-center"
31
+ aria-live="polite"
32
+ >
30
33
  {isError ? (
31
34
  <>
32
35
  {isModern ? (
@@ -45,6 +45,7 @@ const ProcessingStep = (props) => {
45
45
  'm-b-2': isModern,
46
46
  })}
47
47
  type={Typography.TITLE_BODY}
48
+ aria-live="polite"
48
49
  >
49
50
  {psProcessingText}
50
51
  </Title>
@@ -134,7 +134,7 @@ const UploadItem = ({
134
134
  singleFileUpload={singleFileUpload}
135
135
  onDownload={onDownloadFile}
136
136
  >
137
- <div className="np-upload-button">
137
+ <div className="np-upload-button" aria-live="polite">
138
138
  <div className="media">
139
139
  <div className="np-upload-icon media-left">{getIcon()}</div>
140
140
  <div className="media-body text-xs-left" data-testid={TEST_IDS.mediaBody}>
@@ -1,2 +0,0 @@
1
- export function getFocusableElements(focusBoundaryContainer: Node): object;
2
- //# sourceMappingURL=getFocusableElements.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getFocusableElements.d.ts","sourceRoot":"","sources":["../../../../../src/common/focusBoundary/utils/getFocusableElements.js"],"names":[],"mappings":"AAOO,6DAJI,IAAI,GACF,MAAM,CAoBlB"}
@@ -1,3 +0,0 @@
1
- export { getFocusableElements } from "./getFocusableElements";
2
- export { resetFocus } from "./resetFocus";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/common/focusBoundary/utils/index.js"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export function resetFocus({ focusableEls: { first, last }, event }: object): void;
2
- //# sourceMappingURL=resetFocus.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resetFocus.d.ts","sourceRoot":"","sources":["../../../../../src/common/focusBoundary/utils/resetFocus.js"],"names":[],"mappings":"AAOO,qEAJI,MAAM,QAmBhB"}
@@ -1,66 +0,0 @@
1
- import { render, screen, userEvent } from '../../test-utils';
2
-
3
- import FocusBoundary from './FocusBoundary';
4
-
5
- const props = {
6
- onClose: jest.fn(),
7
- };
8
-
9
- describe('FocusBoundary', () => {
10
- beforeEach(() => {
11
- jest.clearAllMocks();
12
- });
13
- it('renders component', () => {
14
- const { container } = render(
15
- <FocusBoundary {...props}>
16
- <a href="test">Test</a>
17
- </FocusBoundary>,
18
- );
19
-
20
- expect(container).toMatchSnapshot();
21
- });
22
-
23
- it('focus on container by default', () => {
24
- render(
25
- <>
26
- <a href="test">not focusable</a>
27
- <FocusBoundary {...props}>
28
- <a href="test">Test</a>
29
- </FocusBoundary>
30
- </>,
31
- );
32
-
33
- expect(focusBoundary()).toHaveFocus();
34
- });
35
-
36
- it('traps the focus when user presses tab', () => {
37
- render(
38
- <>
39
- <a href="test">not focusable</a>
40
- <FocusBoundary {...props}>
41
- <a href="test">firstFocusable</a>
42
- <a href="test">lastFocusable</a>
43
- </FocusBoundary>
44
- </>,
45
- );
46
-
47
- userEvent.tab();
48
- expect(firstFocusableElement()).toHaveFocus();
49
-
50
- userEvent.tab();
51
- expect(lastFocusableElement()).toHaveFocus();
52
-
53
- userEvent.tab();
54
- expect(firstFocusableElement()).toHaveFocus();
55
-
56
- userEvent.tab({ shift: true });
57
- expect(lastFocusableElement()).toHaveFocus();
58
-
59
- userEvent.tab({ shift: true });
60
- expect(firstFocusableElement()).toHaveFocus();
61
- });
62
-
63
- const firstFocusableElement = () => screen.getByText('firstFocusable');
64
- const lastFocusableElement = () => screen.getByText('lastFocusable');
65
- const focusBoundary = () => document.querySelector('.np-focus-boundary');
66
- });
@@ -1,16 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`FocusBoundary renders component 1`] = `
4
- <div>
5
- <div
6
- class="np-focus-boundary outline-none"
7
- tabindex="-1"
8
- >
9
- <a
10
- href="test"
11
- >
12
- Test
13
- </a>
14
- </div>
15
- </div>
16
- `;
@@ -1,25 +0,0 @@
1
- /**
2
- * This function returns the first and the last focusable elements within a node.
3
- *
4
- * @param {Node} focusBoundaryContainer - the area that contains focused elements.
5
- * @returns {object} focusableEls - which contains the first focusable element and the last focusable element. First and last can be the same element if area contains one or none focusable element.
6
- */
7
-
8
- export const getFocusableElements = (focusBoundaryContainer) => {
9
- const focusableEls = { first: focusBoundaryContainer, last: focusBoundaryContainer };
10
-
11
- if (focusBoundaryContainer?.querySelectorAll) {
12
- const allEls = [
13
- ...focusBoundaryContainer.querySelectorAll(
14
- 'a, button, input, textarea, select, details,[tabindex]:not([tabindex="-1"])',
15
- ),
16
- ].filter((element) => !element.hasAttribute('disabled'));
17
-
18
- if (allEls.length > 0) {
19
- [focusableEls.first] = allEls;
20
- focusableEls.last = allEls[allEls.length - 1];
21
- }
22
- }
23
-
24
- return focusableEls;
25
- };
@@ -1,51 +0,0 @@
1
- import { cleanup, render, screen } from '../../../test-utils';
2
-
3
- import { getFocusableElements } from './getFocusableElements';
4
-
5
- describe('getFocusableElements', () => {
6
- afterEach(() => {
7
- cleanup();
8
- });
9
- it('returns first and last focusable element', () => {
10
- const { container } = render(
11
- <>
12
- <div>another element</div>
13
- <a href="test">first</a>
14
- <div>another element</div>
15
- <a href="test">middle</a>
16
- <div>another element</div>
17
- <a href="test">last</a>
18
- <div>another element</div>
19
- </>,
20
- );
21
- getFocusableElements(container);
22
- expect(getFocusableElements(container)).toStrictEqual({
23
- first: first(),
24
- last: last(),
25
- });
26
- });
27
-
28
- it('returns container if there are no focusable elements', () => {
29
- const { container } = render(
30
- <>
31
- <div>another element</div>
32
- </>,
33
- );
34
- getFocusableElements(container);
35
- expect(getFocusableElements(container)).toStrictEqual({
36
- first: container,
37
- last: container,
38
- });
39
- });
40
-
41
- it('returns undefined if container is not provided', () => {
42
- getFocusableElements();
43
- expect(getFocusableElements()).toStrictEqual({
44
- first: undefined,
45
- last: undefined,
46
- });
47
- });
48
-
49
- const first = () => screen.getByText('first');
50
- const last = () => screen.getByText('last');
51
- });
@@ -1,2 +0,0 @@
1
- export { getFocusableElements } from './getFocusableElements';
2
- export { resetFocus } from './resetFocus';
@@ -1,23 +0,0 @@
1
- /**
2
- * This function resets the focus to either last of first focusable elements within a node.
3
- *
4
- * @param {object} focusableEls - contains the first last of first focusable elements within a node.
5
- * @param {object} event - the triggered event
6
- */
7
-
8
- export const resetFocus = ({ focusableEls: { first, last }, event }) => {
9
- const { activeElement } = document;
10
- if (event.shiftKey && activeElement === first) {
11
- if (last) {
12
- last.focus();
13
- }
14
- event.preventDefault();
15
- }
16
-
17
- if (!event.shiftKey && activeElement === last) {
18
- if (first) {
19
- first.focus();
20
- }
21
- event.preventDefault();
22
- }
23
- };
@@ -1,103 +0,0 @@
1
- import { cleanup, render, screen, userEvent } from '../../../test-utils';
2
- import { fakeKeyDownEvent } from '../../fakeEvents';
3
-
4
- import { resetFocus } from './resetFocus';
5
-
6
- describe('resetFocus', () => {
7
- beforeEach(() => {
8
- render(
9
- <>
10
- <a href="test">first</a>
11
- <a href="test">middle</a>
12
- <a href="test">last</a>
13
- </>,
14
- );
15
- });
16
- afterEach(() => {
17
- cleanup();
18
- });
19
- it('set focus to first element when last element is focused and event is tab', () => {
20
- focusOnLast();
21
-
22
- resetFocus({
23
- focusableEls: { first: first(), last: last() },
24
- event: fakeKeyDownEvent({ shiftKey: false }),
25
- });
26
- expect(first()).toHaveFocus();
27
- });
28
-
29
- it('set focus to last element when first element is focused and event is shift + tab', () => {
30
- focusOnFirst();
31
-
32
- resetFocus({
33
- focusableEls: { first: first(), last: last() },
34
- event: fakeKeyDownEvent({ shiftKey: true }),
35
- });
36
- expect(last()).toHaveFocus();
37
- });
38
-
39
- it(`doesn't change focus when first element is focused and event is tab`, () => {
40
- focusOnFirst();
41
-
42
- resetFocus({
43
- focusableEls: { first: first(), last: last() },
44
- event: fakeKeyDownEvent(),
45
- });
46
- expect(first()).toHaveFocus();
47
- });
48
-
49
- it(`doesn't change focus when last element is focused and event is shift+tab`, () => {
50
- focusOnLast();
51
-
52
- resetFocus({
53
- focusableEls: { first: first(), last: last() },
54
- event: fakeKeyDownEvent({ shiftKey: true }),
55
- });
56
- expect(last()).toHaveFocus();
57
- });
58
-
59
- it(`doesn't change focus when middle element is focused and event is shift+tab or tab`, () => {
60
- focusOnMiddle();
61
-
62
- resetFocus({
63
- focusableEls: { first: first(), last: last() },
64
- event: fakeKeyDownEvent({ shiftKey: true }),
65
- });
66
- expect(middle()).toHaveFocus();
67
-
68
- resetFocus({
69
- focusableEls: { first: first(), last: last() },
70
- event: fakeKeyDownEvent(),
71
- });
72
- expect(middle()).toHaveFocus();
73
- });
74
-
75
- it(`doesn't change focus when first is the only element provided`, () => {
76
- focusOnFirst();
77
- resetFocus({
78
- focusableEls: { first: first(), last: undefined },
79
- event: fakeKeyDownEvent({ shiftKey: true }),
80
- });
81
- expect(first()).toHaveFocus();
82
- });
83
-
84
- it(`doesn't change focus when last is the only element provided`, () => {
85
- focusOnLast();
86
- resetFocus({
87
- focusableEls: { first: undefined, last: last() },
88
- event: fakeKeyDownEvent(),
89
- });
90
- expect(last()).toHaveFocus();
91
- });
92
-
93
- const first = () => screen.getByText('first');
94
- const last = () => screen.getByText('last');
95
- const middle = () => screen.getByText('middle');
96
-
97
- const focusOnFirst = () => userEvent.tab();
98
- const focusOnLast = () => userEvent.tab({ shift: true });
99
- const focusOnMiddle = () => {
100
- userEvent.tab();
101
- userEvent.tab();
102
- };
103
- });