@transferwise/components 46.168.0 → 46.168.1

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 (102) hide show
  1. package/build/Prompt/Snackbar/Snackbar.js +4 -7
  2. package/build/Prompt/Snackbar/Snackbar.js.map +1 -1
  3. package/build/Prompt/Snackbar/Snackbar.mjs +4 -7
  4. package/build/Prompt/Snackbar/Snackbar.mjs.map +1 -1
  5. package/build/Prompt/Snackbar/useSnackbarSwipeDismiss.js +33 -46
  6. package/build/Prompt/Snackbar/useSnackbarSwipeDismiss.js.map +1 -1
  7. package/build/Prompt/Snackbar/useSnackbarSwipeDismiss.mjs +34 -47
  8. package/build/Prompt/Snackbar/useSnackbarSwipeDismiss.mjs.map +1 -1
  9. package/build/Provider/Provider.js +1 -24
  10. package/build/Provider/Provider.js.map +1 -1
  11. package/build/Provider/Provider.mjs +1 -24
  12. package/build/Provider/Provider.mjs.map +1 -1
  13. package/build/WithDisplayFormat/WithDisplayFormat.js +20 -8
  14. package/build/WithDisplayFormat/WithDisplayFormat.js.map +1 -1
  15. package/build/WithDisplayFormat/WithDisplayFormat.mjs +20 -8
  16. package/build/WithDisplayFormat/WithDisplayFormat.mjs.map +1 -1
  17. package/build/i18n/cs.json +1 -0
  18. package/build/i18n/cs.json.js +1 -0
  19. package/build/i18n/cs.json.js.map +1 -1
  20. package/build/i18n/cs.json.mjs +1 -0
  21. package/build/i18n/cs.json.mjs.map +1 -1
  22. package/build/i18n/es.json +1 -0
  23. package/build/i18n/es.json.js +1 -0
  24. package/build/i18n/es.json.js.map +1 -1
  25. package/build/i18n/es.json.mjs +1 -0
  26. package/build/i18n/es.json.mjs.map +1 -1
  27. package/build/i18n/id.json +1 -0
  28. package/build/i18n/id.json.js +1 -0
  29. package/build/i18n/id.json.js.map +1 -1
  30. package/build/i18n/id.json.mjs +1 -0
  31. package/build/i18n/id.json.mjs.map +1 -1
  32. package/build/i18n/ja.json +1 -0
  33. package/build/i18n/ja.json.js +1 -0
  34. package/build/i18n/ja.json.js.map +1 -1
  35. package/build/i18n/ja.json.mjs +1 -0
  36. package/build/i18n/ja.json.mjs.map +1 -1
  37. package/build/i18n/nl.json +1 -0
  38. package/build/i18n/nl.json.js +1 -0
  39. package/build/i18n/nl.json.js.map +1 -1
  40. package/build/i18n/nl.json.mjs +1 -0
  41. package/build/i18n/nl.json.mjs.map +1 -1
  42. package/build/i18n/pt.json +1 -0
  43. package/build/i18n/pt.json.js +1 -0
  44. package/build/i18n/pt.json.js.map +1 -1
  45. package/build/i18n/pt.json.mjs +1 -0
  46. package/build/i18n/pt.json.mjs.map +1 -1
  47. package/build/i18n/ro.json +1 -0
  48. package/build/i18n/ro.json.js +1 -0
  49. package/build/i18n/ro.json.js.map +1 -1
  50. package/build/i18n/ro.json.mjs +1 -0
  51. package/build/i18n/ro.json.mjs.map +1 -1
  52. package/build/i18n/ru.json +1 -0
  53. package/build/i18n/ru.json.js +1 -0
  54. package/build/i18n/ru.json.js.map +1 -1
  55. package/build/i18n/ru.json.mjs +1 -0
  56. package/build/i18n/ru.json.mjs.map +1 -1
  57. package/build/i18n/uk.json +1 -0
  58. package/build/i18n/uk.json.js +1 -0
  59. package/build/i18n/uk.json.js.map +1 -1
  60. package/build/i18n/uk.json.mjs +1 -0
  61. package/build/i18n/uk.json.mjs.map +1 -1
  62. package/build/i18n/zh-HK.json +1 -0
  63. package/build/i18n/zh-HK.json.js +1 -0
  64. package/build/i18n/zh-HK.json.js.map +1 -1
  65. package/build/i18n/zh-HK.json.mjs +1 -0
  66. package/build/i18n/zh-HK.json.mjs.map +1 -1
  67. package/build/main.css +1 -0
  68. package/build/styles/Inputs/InputGroup/InputGroup.css +1 -0
  69. package/build/styles/main.css +1 -0
  70. package/build/test-utils/assets/apple-pay-logo.svg +0 -0
  71. package/build/types/Prompt/Snackbar/Snackbar.d.ts.map +1 -1
  72. package/build/types/Prompt/Snackbar/useSnackbarSwipeDismiss.d.ts +6 -8
  73. package/build/types/Prompt/Snackbar/useSnackbarSwipeDismiss.d.ts.map +1 -1
  74. package/build/types/WithDisplayFormat/WithDisplayFormat.d.ts +6 -4
  75. package/build/types/WithDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
  76. package/package.json +15 -15
  77. package/src/InputWithDisplayFormat/_stories/InputWithDisplayFormat.story.tsx +39 -0
  78. package/src/Inputs/InputGroup/InputGroup.css +1 -0
  79. package/src/Inputs/InputGroup/InputGroup.less +1 -0
  80. package/src/Inputs/InputGroup/_stories/InputGroup.test.story.tsx +16 -0
  81. package/src/Inputs/SearchInput/_stories/SearchInput.test.story.tsx +9 -0
  82. package/src/Inputs/SelectInput/_stories/SelectInput.test.story.tsx +12 -0
  83. package/src/MoneyInput/_stories/MoneyInput.test.story.tsx +11 -0
  84. package/src/PhoneNumberInput/_stories/PhoneNumberInput.test.story.tsx +30 -0
  85. package/src/Prompt/Snackbar/Snackbar.test.tsx +1 -69
  86. package/src/Prompt/Snackbar/Snackbar.tsx +4 -6
  87. package/src/Prompt/Snackbar/useSnackbarSwipeDismiss.ts +39 -54
  88. package/src/Provider/Provider.tsx +1 -1
  89. package/src/WithDisplayFormat/WithDisplayFormat.test.js +90 -7
  90. package/src/WithDisplayFormat/WithDisplayFormat.tsx +30 -9
  91. package/src/i18n/cs.json +1 -0
  92. package/src/i18n/es.json +1 -0
  93. package/src/i18n/id.json +1 -0
  94. package/src/i18n/ja.json +1 -0
  95. package/src/i18n/nl.json +1 -0
  96. package/src/i18n/pt.json +1 -0
  97. package/src/i18n/ro.json +1 -0
  98. package/src/i18n/ru.json +1 -0
  99. package/src/i18n/uk.json +1 -0
  100. package/src/i18n/zh-HK.json +1 -0
  101. package/src/main.css +1 -0
  102. package/src/test-utils/assets/apple-pay-logo.svg +0 -0
@@ -770,7 +770,6 @@ describe('Snackbar swipe dismissal', () => {
770
770
 
771
771
  await user.pointer({ keys: '[/MouseLeft]', coords: { clientX: 0, clientY: 200 } });
772
772
 
773
- expect(capture.releasePointerCapture).toHaveBeenCalledWith(1);
774
773
  expect(snackbarProps.onDismissRequest).toHaveBeenCalledTimes(1);
775
774
  expect(container).toHaveStyle({ transform: 'translateY(200px)' });
776
775
  });
@@ -892,7 +891,7 @@ describe('Snackbar swipe dismissal', () => {
892
891
  expect(snackbarProps.onDismissRequest).not.toHaveBeenCalled();
893
892
  });
894
893
 
895
- it.each(['pointercancel', 'lostpointercapture'])('restores the position on %s', async (type) => {
894
+ it.each(['pointercancel'])('restores the position on %s', async (type) => {
896
895
  const { surface, container, snackbarProps } = setupSwipe();
897
896
  mockPointerCapture(surface);
898
897
  await user.pointer([
@@ -911,59 +910,6 @@ describe('Snackbar swipe dismissal', () => {
911
910
  expect(snackbarProps.onDismissRequest).not.toHaveBeenCalled();
912
911
  });
913
912
 
914
- it('recovers when a captured child is removed and capture loss fires on its document', async () => {
915
- const { surface, container, rerender, snackbarProps } = setupSwipe({
916
- media: <span>Drag me</span>,
917
- });
918
- const child = screen.getByText('Drag me');
919
- mockPointerCapture(child);
920
- await user.pointer([
921
- { keys: '[MouseLeft>]', target: child, coords: { clientX: 0, clientY: 0 } },
922
- { coords: { clientX: 0, clientY: 30 } },
923
- ]);
924
- expect(container).toHaveStyle({ transform: 'translateY(30px)' });
925
-
926
- // An unrelated pointer losing capture must not cancel the active gesture.
927
- const unrelatedLoss = new Event('lostpointercapture', { bubbles: true });
928
- Object.defineProperty(unrelatedLoss, 'pointerId', { value: 2 });
929
- fireEvent(surface.ownerDocument, unrelatedLoss);
930
- expect(container).toHaveStyle({ transform: 'translateY(30px)' });
931
-
932
- rerender(<Snackbar {...snackbarProps} media={undefined} />);
933
- expect(child).not.toBeInTheDocument();
934
- const captureLoss = new Event('lostpointercapture', { bubbles: true });
935
- Object.defineProperty(captureLoss, 'pointerId', { value: 1 });
936
- fireEvent(surface.ownerDocument, captureLoss);
937
-
938
- expect(container).toHaveStyle({ transform: '' });
939
- expect(container).toHaveClass('wds-Snackbar--swipe-settle');
940
- expect(snackbarProps.onDismissRequest).not.toHaveBeenCalled();
941
- await user.pointer({ keys: '[/MouseLeft]', target: document.body });
942
- await user.pointer([
943
- { keys: '[MouseLeft>]', target: surface, coords: { clientX: 0, clientY: 0 } },
944
- { coords: { clientX: 0, clientY: 50 } },
945
- '[/MouseLeft]',
946
- ]);
947
- expect(snackbarProps.onDismissRequest).toHaveBeenCalledTimes(1);
948
- });
949
-
950
- it('removes its document capture-loss listener on unmount', () => {
951
- const addListener = jest.spyOn(document, 'addEventListener');
952
- const removeListener = jest.spyOn(document, 'removeEventListener');
953
- try {
954
- const { unmount } = setupSwipe();
955
- const listener = addListener.mock.calls.find(([type]) => type === 'lostpointercapture')?.[1];
956
- expect(listener).toEqual(expect.any(Function));
957
-
958
- unmount();
959
-
960
- expect(removeListener).toHaveBeenCalledWith('lostpointercapture', listener);
961
- } finally {
962
- addListener.mockRestore();
963
- removeListener.mockRestore();
964
- }
965
- });
966
-
967
913
  it('ignores secondary pointers while retaining the primary gesture', async () => {
968
914
  const { surface, container, snackbarProps } = setupSwipe();
969
915
  const capture = mockPointerCapture(surface);
@@ -995,20 +941,6 @@ describe('Snackbar swipe dismissal', () => {
995
941
  expect(snackbarProps.onDismissRequest).not.toHaveBeenCalled();
996
942
  });
997
943
 
998
- it('clears the drag state after the exit finishes', async () => {
999
- const { surface, container, rerender, snackbarProps } = setupSwipe();
1000
- await user.pointer([
1001
- { keys: '[MouseLeft>]', target: surface, coords: { clientX: 0, clientY: 0 } },
1002
- { coords: { clientX: 0, clientY: 50 } },
1003
- '[/MouseLeft]',
1004
- ]);
1005
- rerender(<Snackbar {...snackbarProps} visible={false} />);
1006
- advanceTimers(SNACKBAR_EXIT_DURATION);
1007
- expect(container).toHaveStyle({ transform: '' });
1008
- expect(container).not.toHaveClass('wds-Snackbar--swipe-dismiss');
1009
- expect(snackbarProps.onExited).toHaveBeenCalledTimes(1);
1010
- });
1011
-
1012
944
  it('keeps dragging across a render and uses the latest dismissal callback', async () => {
1013
945
  const { surface, container, rerender, snackbarProps } = setupSwipe();
1014
946
  await user.pointer([
@@ -105,14 +105,14 @@ export const Snackbar = ({
105
105
  visible,
106
106
  });
107
107
  const {
108
- clearSwipePosition,
108
+ cancelSwipe,
109
109
  containerRef,
110
110
  handleClickCapture,
111
111
  handlePointerCancel,
112
112
  handlePointerDown,
113
113
  handlePointerMove,
114
114
  handlePointerUp,
115
- } = useSnackbarSwipeDismiss({ onDismissRequest, onSwipeChange: setSwiping, visible });
115
+ } = useSnackbarSwipeDismiss({ onDismissRequest, onSwipeChange: setSwiping });
116
116
 
117
117
  useEffect(() => {
118
118
  if (!visible) {
@@ -187,10 +187,8 @@ export const Snackbar = ({
187
187
  }}
188
188
  unmountOnExit
189
189
  onEntered={handleEntered}
190
- onExited={() => {
191
- clearSwipePosition();
192
- onExited();
193
- }}
190
+ onExit={cancelSwipe}
191
+ onExited={onExited}
194
192
  >
195
193
  <PrimitivePrompt
196
194
  ref={surfaceRef}
@@ -1,4 +1,4 @@
1
- import { useCallback, useEffect, useRef } from 'react';
1
+ import { useRef } from 'react';
2
2
 
3
3
  import { SNACKBAR_SWIPE_DISMISS_THRESHOLD } from './constants';
4
4
 
@@ -14,47 +14,42 @@ type SwipePointer = {
14
14
  };
15
15
 
16
16
  /**
17
- * Captures one primary pointer and follows downward, mostly vertical movement without re-rendering.
18
- * Release dismisses at half the surface height; shorter/cancelled gestures settle back into place.
19
- * The outer wrapper moves independently of entry/exit motion, and a committed swipe consumes its
20
- * follow-up click so dragging from the action cannot activate it.
17
+ * Follows one primary pointer's downward, mostly vertical movement without re-rendering.
18
+ * Release dismisses at half the surface height; shorter or cancelled gestures settle back.
19
+ * A drag consumes its follow-up click, so dragging from the action cannot activate it.
21
20
  */
22
21
  const useSnackbarSwipeDismiss = ({
23
22
  onDismissRequest,
24
23
  onSwipeChange,
25
- visible,
26
24
  }: {
27
25
  onDismissRequest: () => void;
28
26
  /** Reports when a gesture starts and ends so auto-dismiss can pause beneath the pointer. */
29
27
  onSwipeChange: (swiping: boolean) => void;
30
- visible: boolean;
31
28
  }) => {
32
29
  const containerRef = useRef<HTMLDivElement>(null);
33
30
  const pointerRef = useRef<SwipePointer | null>(null);
34
31
  const suppressClick = useRef(false);
35
32
 
36
- const clearSwipePosition = useCallback(() => {
37
- const pointer = pointerRef.current;
33
+ const endGesture = () => {
38
34
  pointerRef.current = null;
39
- if (pointer) {
40
- if (pointer.target.hasPointerCapture?.(pointer.id)) {
41
- pointer.target.releasePointerCapture(pointer.id);
42
- }
43
- onSwipeChange(false);
44
- }
45
- suppressClick.current = false;
46
- containerRef.current?.classList.remove(DISMISS_CLASS, SETTLE_CLASS);
35
+ onSwipeChange(false);
36
+ };
37
+
38
+ const settle = () => {
39
+ containerRef.current?.classList.add(SETTLE_CLASS);
47
40
  containerRef.current?.style.removeProperty('transform');
48
- }, [onSwipeChange]);
41
+ };
49
42
 
50
43
  const handlePointerDown = (event: React.PointerEvent<HTMLDivElement>) => {
51
44
  if (event.button !== 0 || !event.isPrimary || pointerRef.current) {
52
45
  return;
53
46
  }
54
47
 
55
- clearSwipePosition();
56
48
  const target = event.target as Element;
49
+ // Keeps move/up events coming when a mouse leaves the Snackbar mid-drag.
57
50
  target.setPointerCapture?.(event.pointerId);
51
+ containerRef.current?.classList.remove(DISMISS_CLASS, SETTLE_CLASS);
52
+ suppressClick.current = false;
58
53
  pointerRef.current = {
59
54
  id: event.pointerId,
60
55
  target,
@@ -86,13 +81,12 @@ const useSnackbarSwipeDismiss = ({
86
81
  return;
87
82
  }
88
83
 
84
+ endGesture();
89
85
  const offsetY = event.clientY - pointer.startY;
90
86
  const offsetX = event.clientX - pointer.startX;
91
87
  const container = containerRef.current;
92
- const bounds = pointer.target.closest('a, button')?.getBoundingClientRect();
93
- clearSwipePosition();
94
-
95
88
  if (offsetY >= pointer.threshold && offsetY > Math.abs(offsetX)) {
89
+ suppressClick.current = true;
96
90
  if (container) {
97
91
  // Include wrapper padding and the safe area, not only the surface, to clear the viewport.
98
92
  container.classList.add(DISMISS_CLASS);
@@ -101,10 +95,11 @@ const useSnackbarSwipeDismiss = ({
101
95
  `translateY(${Math.max(offsetY, container.offsetHeight)}px)`,
102
96
  );
103
97
  }
104
- suppressClick.current = true;
105
98
  onDismissRequest();
106
99
  } else {
107
- // Capture retargets clicks to the pressed control even when released outside it.
100
+ // Capture retargets the click to the pressed control even when released outside it,
101
+ // unlike a native button; cancel it in that case.
102
+ const bounds = pointer.target.closest('a, button')?.getBoundingClientRect();
108
103
  suppressClick.current =
109
104
  !!bounds &&
110
105
  (offsetX !== 0 || offsetY !== 0) &&
@@ -112,40 +107,30 @@ const useSnackbarSwipeDismiss = ({
112
107
  event.clientX > bounds.right ||
113
108
  event.clientY < bounds.top ||
114
109
  event.clientY > bounds.bottom);
115
- container?.classList.add(SETTLE_CLASS);
110
+ settle();
116
111
  }
117
112
  };
118
113
 
119
- const handlePointerCancel = useCallback(
120
- (event: Pick<PointerEvent, 'pointerId'>) => {
121
- if (pointerRef.current?.id !== event.pointerId) {
122
- return;
123
- }
114
+ const handlePointerCancel = (event: React.PointerEvent<HTMLDivElement>) => {
115
+ if (pointerRef.current?.id !== event.pointerId) {
116
+ return;
117
+ }
118
+
119
+ endGesture();
120
+ settle();
121
+ };
124
122
 
125
- clearSwipePosition();
126
- containerRef.current?.classList.add(SETTLE_CLASS);
127
- },
128
- [clearSwipePosition],
129
- );
130
-
131
- useEffect(() => {
132
- if (visible) {
133
- clearSwipePosition();
134
- } else if (pointerRef.current) {
135
- // An exit starting mid-gesture (timeout, Escape, replacement) ends it without dismissing again.
136
- handlePointerCancel({ pointerId: pointerRef.current.id });
123
+ /** Ends a gesture still in progress when the Snackbar starts exiting for another reason. */
124
+ const cancelSwipe = () => {
125
+ const pointer = pointerRef.current;
126
+ if (!pointer) {
127
+ return;
137
128
  }
138
- }, [visible, clearSwipePosition, handlePointerCancel]);
139
-
140
- useEffect(() => {
141
- // Removed descendants report capture loss on their document, not the Snackbar surface.
142
- const ownerDocument = containerRef.current?.ownerDocument;
143
- ownerDocument?.addEventListener('lostpointercapture', handlePointerCancel);
144
- return () => {
145
- ownerDocument?.removeEventListener('lostpointercapture', handlePointerCancel);
146
- clearSwipePosition();
147
- };
148
- }, [clearSwipePosition, handlePointerCancel]);
129
+
130
+ pointer.target.releasePointerCapture?.(pointer.id);
131
+ endGesture();
132
+ settle();
133
+ };
149
134
 
150
135
  const handleClickCapture = (event: React.MouseEvent<HTMLDivElement>) => {
151
136
  if (suppressClick.current && event.detail > 0) {
@@ -156,7 +141,7 @@ const useSnackbarSwipeDismiss = ({
156
141
  };
157
142
 
158
143
  return {
159
- clearSwipePosition,
144
+ cancelSwipe,
160
145
  containerRef,
161
146
  handleClickCapture,
162
147
  handlePointerCancel,
@@ -1,6 +1,6 @@
1
1
  import { IntlProvider, ResolvedIntlConfig } from 'react-intl';
2
2
 
3
- import { adjustLocale, DEFAULT_LOCALE, getDirectionFromLocale } from '../common';
3
+ import { adjustLocale, DEFAULT_LOCALE, getDirectionFromLocale } from '../common/Locale';
4
4
  import en from '../i18n/en.json';
5
5
 
6
6
  import { DirectionProvider } from './Direction';
@@ -5,13 +5,11 @@ import WithDisplayFormat from '.';
5
5
 
6
6
  const user = userEvent;
7
7
 
8
- const setup = (props) =>
9
- render(
10
- <WithDisplayFormat
11
- {...props}
12
- render={(renderProps) => <Input {...renderProps} name="input" />}
13
- />,
14
- );
8
+ const renderInput = (props) => (
9
+ <WithDisplayFormat {...props} render={(renderProps) => <Input {...renderProps} name="input" />} />
10
+ );
11
+
12
+ const setup = (props) => render(renderInput(props));
15
13
 
16
14
  describe('InputWithTextFormat (React Testing Library)', () => {
17
15
  const initialProps = {
@@ -26,6 +24,91 @@ describe('InputWithTextFormat (React Testing Library)', () => {
26
24
  jest.clearAllMocks();
27
25
  });
28
26
 
27
+ it('updates the displayed value when the value prop changes', () => {
28
+ const { rerender } = setup({ ...initialProps, value: '123' });
29
+
30
+ expect(screen.getByRole('textbox')).toHaveValue('12-3');
31
+
32
+ rerender(renderInput({ ...initialProps, value: '456' }));
33
+
34
+ expect(screen.getByRole('textbox')).toHaveValue('45-6');
35
+ });
36
+
37
+ it('preserves the current value and resets undo history when the pattern changes', async () => {
38
+ const props = { ...initialProps, displayPattern: '**-**' };
39
+ const { rerender } = setup(props);
40
+ const input = screen.getByRole('textbox');
41
+
42
+ await user.type(input, '123');
43
+ rerender(renderInput({ ...props, displayPattern: '**/**' }));
44
+
45
+ expect(input).toHaveValue('12/3');
46
+ await user.keyboard('{Control>}z{/Control}');
47
+ expect(input).toHaveValue('12/3');
48
+ });
49
+
50
+ it('uses the incoming value when the value and pattern change together', () => {
51
+ const props = { ...initialProps, value: '123', displayPattern: '**-**' };
52
+ const { rerender } = setup(props);
53
+
54
+ rerender(renderInput({ ...props, value: '4567', displayPattern: '**/**' }));
55
+
56
+ expect(screen.getByRole('textbox')).toHaveValue('45/67');
57
+ });
58
+
59
+ it('resets undo history when the value prop changes externally', async () => {
60
+ const props = { ...initialProps, displayPattern: '**-**' };
61
+ const { rerender } = setup(props);
62
+ const input = screen.getByRole('textbox');
63
+
64
+ await user.type(input, '123');
65
+ rerender(renderInput({ ...props, value: '456' }));
66
+
67
+ expect(input).toHaveValue('45-6');
68
+ await user.keyboard('{Control>}z{/Control}');
69
+ expect(input).toHaveValue('45-6');
70
+ });
71
+
72
+ it('preserves undo history when the parent echoes an onChange value', async () => {
73
+ const ControlledInput = () => {
74
+ const [value, setValue] = React.useState('');
75
+ return renderInput({ ...initialProps, value, displayPattern: '***', onChange: setValue });
76
+ };
77
+
78
+ render(<ControlledInput />);
79
+ const input = screen.getByRole('textbox');
80
+
81
+ await user.type(input, '123');
82
+ await user.keyboard('{Control>}z{/Control}');
83
+
84
+ expect(input).toHaveValue('12');
85
+ });
86
+
87
+ it('reformats a pasted value when the parent removes spaces from the onChange value', async () => {
88
+ const ControlledInput = () => {
89
+ const [value, setValue] = React.useState('');
90
+
91
+ const handleChange = (nextValue) => {
92
+ setValue(nextValue.replaceAll(' ', ''));
93
+ };
94
+
95
+ return renderInput({
96
+ ...initialProps,
97
+ value,
98
+ displayPattern: '**-**-**',
99
+ onChange: handleChange,
100
+ });
101
+ };
102
+
103
+ render(<ControlledInput />);
104
+ const input = screen.getByRole('textbox');
105
+
106
+ await user.click(input);
107
+ await user.paste('00 00 00');
108
+
109
+ await waitFor(() => expect(input).toHaveValue('00-00-00'));
110
+ });
111
+
29
112
  [
30
113
  { value: '123', expectedValue: '12-3', displayPattern: '**-**-**' },
31
114
  { value: '1234', expectedValue: '12-34', displayPattern: '**-**-**' },
@@ -20,6 +20,7 @@ export type EventType =
20
20
 
21
21
  interface WithDisplayFormatState {
22
22
  value: string;
23
+ prevValue: string;
23
24
  historyNavigator: HistoryNavigator;
24
25
  prevDisplayPattern: string;
25
26
  triggerType: EventType;
@@ -76,6 +77,7 @@ class WithDisplayFormat<T extends TextElementProps> extends React.Component<
76
77
  const unformattedValue = unformatWithPattern(props.value ?? '', props.displayPattern);
77
78
  this.state = {
78
79
  value: formatWithPattern(unformattedValue, props.displayPattern),
80
+ prevValue: props.value ?? '',
79
81
  historyNavigator: new HistoryNavigator(),
80
82
  prevDisplayPattern: props.displayPattern,
81
83
  triggerType: 'Initial',
@@ -87,19 +89,38 @@ class WithDisplayFormat<T extends TextElementProps> extends React.Component<
87
89
  }
88
90
 
89
91
  static getDerivedStateFromProps(
90
- { displayPattern }: WithDisplayFormatProps,
91
- { prevDisplayPattern = displayPattern, value, historyNavigator }: WithDisplayFormatState,
92
+ { displayPattern, value: propValue }: WithDisplayFormatProps,
93
+ {
94
+ prevDisplayPattern = displayPattern,
95
+ prevValue,
96
+ value,
97
+ historyNavigator,
98
+ }: WithDisplayFormatState,
92
99
  ) {
93
- if (prevDisplayPattern !== displayPattern) {
94
- const unFormattedValue = unformatWithPattern(value, prevDisplayPattern);
95
- historyNavigator.reset();
100
+ const nextValue = propValue ?? '';
101
+ const displayPatternChanged = prevDisplayPattern !== displayPattern;
102
+ const valueChanged = prevValue !== nextValue;
103
+
104
+ if (displayPatternChanged || valueChanged) {
105
+ const unformattedValue = valueChanged
106
+ ? unformatWithPattern(nextValue, displayPattern)
107
+ : unformatWithPattern(value, prevDisplayPattern);
108
+ const isEchoOfCurrentValue =
109
+ valueChanged && unformattedValue === unformatWithPattern(value, displayPattern);
110
+
111
+ if (displayPatternChanged || (valueChanged && !isEchoOfCurrentValue)) {
112
+ historyNavigator.reset([unformattedValue]);
113
+ }
96
114
 
97
115
  return {
98
116
  prevDisplayPattern: displayPattern,
99
- value: formatWithPattern(unFormattedValue, displayPattern),
100
- triggerType: null,
101
- triggerEvent: null,
102
- pastedLength: 0,
117
+ prevValue: nextValue,
118
+ value: formatWithPattern(unformattedValue, displayPattern),
119
+ ...(displayPatternChanged && {
120
+ triggerType: null,
121
+ triggerEvent: null,
122
+ pastedLength: 0,
123
+ }),
103
124
  };
104
125
  }
105
126
  return null;
package/src/i18n/cs.json CHANGED
@@ -38,6 +38,7 @@
38
38
  "neptune.PhoneNumberInput.phoneNumberPrefix": "Předčíslí",
39
39
  "neptune.Select.searchPlaceholder": "Hledat...",
40
40
  "neptune.SelectInput.noResultsFound": "Nebyly nalezeny žádné výsledky",
41
+ "neptune.Snackbar.escapeDismissHint": "Pro zavření stiskněte Esc.",
41
42
  "neptune.StatusIcon.iconLabel.error": "Chyba:",
42
43
  "neptune.StatusIcon.iconLabel.information": "Informace:",
43
44
  "neptune.StatusIcon.iconLabel.pending": "Vyřizuje se:",
package/src/i18n/es.json CHANGED
@@ -38,6 +38,7 @@
38
38
  "neptune.PhoneNumberInput.phoneNumberPrefix": "Prefijo",
39
39
  "neptune.Select.searchPlaceholder": "Buscar...",
40
40
  "neptune.SelectInput.noResultsFound": "No se han encontrado resultados",
41
+ "neptune.Snackbar.escapeDismissHint": "Pulsa Escape para cerrar.",
41
42
  "neptune.StatusIcon.iconLabel.error": "Error:",
42
43
  "neptune.StatusIcon.iconLabel.information": "Información:",
43
44
  "neptune.StatusIcon.iconLabel.pending": "Pendiente:",
package/src/i18n/id.json CHANGED
@@ -38,6 +38,7 @@
38
38
  "neptune.PhoneNumberInput.phoneNumberPrefix": "Awalan",
39
39
  "neptune.Select.searchPlaceholder": "Cari...",
40
40
  "neptune.SelectInput.noResultsFound": "Hasil tidak ditemukan",
41
+ "neptune.Snackbar.escapeDismissHint": "Tekan Escape untuk menutup.",
41
42
  "neptune.StatusIcon.iconLabel.error": "Kesalahan:",
42
43
  "neptune.StatusIcon.iconLabel.information": "Informasi:",
43
44
  "neptune.StatusIcon.iconLabel.pending": "Tertunda:",
package/src/i18n/ja.json CHANGED
@@ -38,6 +38,7 @@
38
38
  "neptune.PhoneNumberInput.phoneNumberPrefix": "プレフィックス",
39
39
  "neptune.Select.searchPlaceholder": "検索する... ",
40
40
  "neptune.SelectInput.noResultsFound": "結果が見つかりませんでした",
41
+ "neptune.Snackbar.escapeDismissHint": "Escキーを押して閉じます。",
41
42
  "neptune.StatusIcon.iconLabel.error": "エラー:",
42
43
  "neptune.StatusIcon.iconLabel.information": "情報:",
43
44
  "neptune.StatusIcon.iconLabel.pending": "保留中:",
package/src/i18n/nl.json CHANGED
@@ -38,6 +38,7 @@
38
38
  "neptune.PhoneNumberInput.phoneNumberPrefix": "Voorvoegsel",
39
39
  "neptune.Select.searchPlaceholder": "Zoeken...",
40
40
  "neptune.SelectInput.noResultsFound": "Geen resultaten gevonden",
41
+ "neptune.Snackbar.escapeDismissHint": "Druk op Escape om te verwijderen.",
41
42
  "neptune.StatusIcon.iconLabel.error": "Fout:",
42
43
  "neptune.StatusIcon.iconLabel.information": "Informatie:",
43
44
  "neptune.StatusIcon.iconLabel.pending": "In behandeling:",
package/src/i18n/pt.json CHANGED
@@ -38,6 +38,7 @@
38
38
  "neptune.PhoneNumberInput.phoneNumberPrefix": "Prefixo",
39
39
  "neptune.Select.searchPlaceholder": "Buscar...",
40
40
  "neptune.SelectInput.noResultsFound": "Nenhum resultado encontrado",
41
+ "neptune.Snackbar.escapeDismissHint": "Pressione Esc para fechar.",
41
42
  "neptune.StatusIcon.iconLabel.error": "Erro:",
42
43
  "neptune.StatusIcon.iconLabel.information": "Informação:",
43
44
  "neptune.StatusIcon.iconLabel.pending": "Pendente:",
package/src/i18n/ro.json CHANGED
@@ -38,6 +38,7 @@
38
38
  "neptune.PhoneNumberInput.phoneNumberPrefix": "Prefix",
39
39
  "neptune.Select.searchPlaceholder": "Caută...",
40
40
  "neptune.SelectInput.noResultsFound": "Nu s-a găsit niciun rezultat",
41
+ "neptune.Snackbar.escapeDismissHint": "Apasă pe Escape pentru a închide.",
41
42
  "neptune.StatusIcon.iconLabel.error": "Eroare:",
42
43
  "neptune.StatusIcon.iconLabel.information": "Informații:",
43
44
  "neptune.StatusIcon.iconLabel.pending": "În așteptare:",
package/src/i18n/ru.json CHANGED
@@ -38,6 +38,7 @@
38
38
  "neptune.PhoneNumberInput.phoneNumberPrefix": "Код страны",
39
39
  "neptune.Select.searchPlaceholder": "Поиск...",
40
40
  "neptune.SelectInput.noResultsFound": "Ничего не найдено",
41
+ "neptune.Snackbar.escapeDismissHint": "Нажмите Escape, чтобы закрыть.",
41
42
  "neptune.StatusIcon.iconLabel.error": "Ошибка:",
42
43
  "neptune.StatusIcon.iconLabel.information": "Информация:",
43
44
  "neptune.StatusIcon.iconLabel.pending": "В ожидании:",
package/src/i18n/uk.json CHANGED
@@ -38,6 +38,7 @@
38
38
  "neptune.PhoneNumberInput.phoneNumberPrefix": "Префікс",
39
39
  "neptune.Select.searchPlaceholder": "Пошук…",
40
40
  "neptune.SelectInput.noResultsFound": "Нічого не знайдено",
41
+ "neptune.Snackbar.escapeDismissHint": "Натисніть Escape, щоб закрити.",
41
42
  "neptune.StatusIcon.iconLabel.error": "Помилка:",
42
43
  "neptune.StatusIcon.iconLabel.information": "Інформація:",
43
44
  "neptune.StatusIcon.iconLabel.pending": "Обробка:",
@@ -38,6 +38,7 @@
38
38
  "neptune.PhoneNumberInput.phoneNumberPrefix": "前綴",
39
39
  "neptune.Select.searchPlaceholder": "搜尋…",
40
40
  "neptune.SelectInput.noResultsFound": "找不到任何結果",
41
+ "neptune.Snackbar.escapeDismissHint": "按下Escape鍵以關閉。",
41
42
  "neptune.StatusIcon.iconLabel.error": "錯誤:",
42
43
  "neptune.StatusIcon.iconLabel.information": "資訊:",
43
44
  "neptune.StatusIcon.iconLabel.pending": "處理中:",
package/src/main.css CHANGED
@@ -29649,6 +29649,7 @@ button.np-option {
29649
29649
  display: inline-grid;
29650
29650
  inline-size: 100%;
29651
29651
  grid-auto-columns: minmax(0, 1fr);
29652
+ isolation: isolate;
29652
29653
  /* Prevent unwanted `group-hover/input` triggers */
29653
29654
  border-radius: var(--radius-full);
29654
29655
  }
File without changes