@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.
- package/build/development/shared/components/TextArea/index.js +23 -4
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/style.css +1 -0
- package/build/development/web.bundle.js +1 -1
- package/build/production/shared/components/TextArea/index.js +16 -4
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/style.css +1 -1
- package/build/production/style.css.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/build/types-code/shared/components/TextArea/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/shared/components/TextArea/index.tsx +22 -3
- package/src/shared/components/TextArea/style.scss +1 -0
package/package.json
CHANGED
|
@@ -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
|
-
//
|
|
62
|
-
|
|
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
|
-
|
|
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
|
|