@dr.pogodin/react-utils 1.43.22 → 1.43.23

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.
@@ -7,6 +7,7 @@ type Props = {
7
7
  onChange?: ChangeEventHandler<HTMLTextAreaElement>;
8
8
  onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;
9
9
  placeholder?: string;
10
+ testId?: string;
10
11
  theme: Theme<ThemeKeyT>;
11
12
  value?: string;
12
13
  };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.43.22",
2
+ "version": "1.43.23",
3
3
  "bin": {
4
4
  "react-utils-build": "bin/build.js",
5
5
  "react-utils-setup": "bin/setup.js"
@@ -4,6 +4,7 @@ import {
4
4
  type FunctionComponent,
5
5
  type KeyboardEventHandler,
6
6
  useEffect,
7
+ useLayoutEffect,
7
8
  useRef,
8
9
  useState,
9
10
  } from 'react';
@@ -23,6 +24,7 @@ type Props = {
23
24
  onChange?: ChangeEventHandler<HTMLTextAreaElement>;
24
25
  onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;
25
26
  placeholder?: string;
27
+ testId?: string;
26
28
  theme: Theme<ThemeKeyT>;
27
29
  value?: string;
28
30
  };
@@ -33,6 +35,7 @@ const TextArea: FunctionComponent<Props> = ({
33
35
  onChange,
34
36
  onKeyDown,
35
37
  placeholder,
38
+ testId,
36
39
  theme,
37
40
  value,
38
41
  }) => {
@@ -58,8 +61,14 @@ const TextArea: FunctionComponent<Props> = ({
58
61
  };
59
62
  }, []);
60
63
 
61
- // This resizes the text area when its content is modified.
62
- useEffect(() => {
64
+ // Resizes the text area when its content is modified.
65
+ //
66
+ // NOTE: useLayoutEffect() instead of useEffect() makes difference here,
67
+ // as it helps to avoid visible "content/height" jumps (i.e. with just
68
+ // useEffect() it becomes visible how the content is modified first,
69
+ // and then input height is incremented, if necessary).
70
+ // See: https://github.com/birdofpreyru/react-utils/issues/313
71
+ useLayoutEffect(() => {
63
72
  const el = hiddenAreaRef.current;
64
73
  if (el) setHeight(el.scrollHeight);
65
74
  }, [localValue]);
@@ -74,10 +83,20 @@ const TextArea: FunctionComponent<Props> = ({
74
83
  // of the primary textarea's height.
75
84
  readOnly
76
85
  ref={hiddenAreaRef}
77
- value={localValue}
86
+
87
+ // The "-1" value of "tabIndex" removes this hidden text area from
88
+ // the tab-focus-chain.
89
+ tabIndex={-1}
90
+
91
+ // NOTE: With empty string value ("") the scrolling height of this text
92
+ // area is zero, thus collapsing <TextArea> height below the single line
93
+ // input height. To avoid it we fallback to whitespace (" ") character
94
+ // here.
95
+ value={localValue || ' '}
78
96
  />
79
97
  <textarea
80
98
  className={theme.textarea}
99
+ data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}
81
100
  disabled={disabled}
82
101
  onBlur={onBlur}
83
102
 
@@ -19,6 +19,7 @@
19
19
  overflow: hidden;
20
20
  padding: 0.3em 0.3em calc(0.3em + 1px);
21
21
  resize: none;
22
+ width: 100%;
22
23
 
23
24
  &:focus {
24
25
  border-color: blue;