@instructure/ui-text-area 11.7.3-snapshot-25 → 11.7.3-snapshot-27
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/CHANGELOG.md +5 -2
- package/es/TextArea/v1/index.js +127 -122
- package/es/TextArea/v1/styles.js +4 -2
- package/es/TextArea/v1/theme.js +33 -32
- package/es/TextArea/v2/index.js +57 -62
- package/es/TextArea/v2/styles.js +7 -5
- package/es/TextArea/v2/theme.js +33 -32
- package/lib/TextArea/v1/index.js +127 -122
- package/lib/TextArea/v1/styles.js +4 -2
- package/lib/TextArea/v1/theme.js +33 -32
- package/lib/TextArea/v2/index.js +58 -62
- package/lib/TextArea/v2/styles.js +7 -5
- package/lib/TextArea/v2/theme.js +33 -32
- package/package.json +15 -15
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [11.7.3-snapshot-
|
|
6
|
+
## [11.7.3-snapshot-27](https://github.com/instructure/instructure-ui/compare/v11.7.2...v11.7.3-snapshot-27) (2026-05-05)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **many:** update dependencies, remove lots of Babel plugins, remove Webpack 4 support ([f916fca](https://github.com/instructure/instructure-ui/commit/f916fcafdddcb2d7de401f93e8ff92cfdfa47bba))
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
|
package/es/TextArea/v1/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _dec, _dec2, _class
|
|
1
|
+
var _dec, _dec2, _class;
|
|
2
2
|
/*
|
|
3
3
|
* The MIT License (MIT)
|
|
4
4
|
*
|
|
@@ -40,87 +40,36 @@ category: components
|
|
|
40
40
|
---
|
|
41
41
|
**/
|
|
42
42
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
43
|
-
let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec(_class = _dec2(_class =
|
|
43
|
+
let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec(_class = _dec2(_class = class TextArea extends Component {
|
|
44
|
+
static displayName = "TextArea";
|
|
45
|
+
static componentId = 'TextArea';
|
|
46
|
+
static allowedProps = allowedProps;
|
|
47
|
+
static defaultProps = {
|
|
48
|
+
size: 'medium',
|
|
49
|
+
autoGrow: true,
|
|
50
|
+
resize: 'none',
|
|
51
|
+
inline: false,
|
|
52
|
+
messages: [],
|
|
53
|
+
disabled: false,
|
|
54
|
+
readOnly: false,
|
|
55
|
+
layout: 'stacked',
|
|
56
|
+
required: false
|
|
57
|
+
};
|
|
58
|
+
_listener;
|
|
59
|
+
_request;
|
|
60
|
+
_defaultId;
|
|
61
|
+
_textareaResizeListener;
|
|
62
|
+
_debounced;
|
|
63
|
+
_textarea = null;
|
|
64
|
+
_container = null;
|
|
65
|
+
_height;
|
|
66
|
+
_manuallyResized = false;
|
|
67
|
+
_highlightRef = null;
|
|
68
|
+
myObserver = null;
|
|
69
|
+
resizeTimeout;
|
|
70
|
+
ref = null;
|
|
44
71
|
constructor(props) {
|
|
45
72
|
super(props);
|
|
46
|
-
this._listener = void 0;
|
|
47
|
-
this._request = void 0;
|
|
48
|
-
this._defaultId = void 0;
|
|
49
|
-
this._textareaResizeListener = void 0;
|
|
50
|
-
this._debounced = void 0;
|
|
51
|
-
this._textarea = null;
|
|
52
|
-
this._container = null;
|
|
53
|
-
this._height = void 0;
|
|
54
|
-
this._manuallyResized = false;
|
|
55
|
-
this._highlightRef = null;
|
|
56
|
-
this.myObserver = null;
|
|
57
|
-
this.resizeTimeout = void 0;
|
|
58
|
-
this.ref = null;
|
|
59
|
-
this._textareaResize = () => {
|
|
60
|
-
const textareaHeight = this._textarea.style.height;
|
|
61
|
-
if (textareaHeight !== '' && textareaHeight !== this._height) {
|
|
62
|
-
this._manuallyResized = true;
|
|
63
|
-
this._textarea.style.overflowY = 'auto';
|
|
64
|
-
|
|
65
|
-
// update container minHeight to ensure focus ring always wraps input
|
|
66
|
-
this._container.style.minHeight = textareaHeight;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
this.grow = () => {
|
|
70
|
-
if (!this._textarea || this._manuallyResized) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
const offset = this._textarea.offsetHeight - this._textarea.clientHeight;
|
|
74
|
-
let height = '';
|
|
75
|
-
|
|
76
|
-
// Notes:
|
|
77
|
-
// 1. height has to be reset to `auto` every time this method runs, or scrollHeight will not reset
|
|
78
|
-
// 2. `this._textarea.scrollHeight` will not reset if assigned to a variable; it needs to be written out each time
|
|
79
|
-
this._textarea.style.height = 'auto';
|
|
80
|
-
this._textarea.style.overflowY = 'hidden'; // hide scrollbars for autoGrow textareas
|
|
81
|
-
height = this._textarea.scrollHeight + offset + 'px';
|
|
82
|
-
const maxHeight = this.props.maxHeight ? px(this.props.maxHeight, this._container) : void 0;
|
|
83
|
-
if (this.props.maxHeight && maxHeight !== void 0 && this._textarea.scrollHeight > maxHeight) {
|
|
84
|
-
this._textarea.style.overflowY = 'auto'; // add scroll if scrollHeight exceeds maxHeight in pixels
|
|
85
|
-
} else if (this.props.height) {
|
|
86
|
-
if (this._textarea.value === '') {
|
|
87
|
-
height = this.props.height;
|
|
88
|
-
} else if (px(this.props.height, this._container) > this._textarea.scrollHeight) {
|
|
89
|
-
this._textarea.style.overflowY = 'auto'; // add scroll if scrollHeight exceeds height in pixels
|
|
90
|
-
height = this.props.height;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// preserve container height to prevent scroll jumping on long textareas,
|
|
95
|
-
// but make sure container doesn't exceed maxHeight prop
|
|
96
|
-
const heightExceedsMax = maxHeight !== void 0 && px(height) > maxHeight;
|
|
97
|
-
if (!heightExceedsMax) {
|
|
98
|
-
this._container.style.minHeight = height;
|
|
99
|
-
}
|
|
100
|
-
this._height = height;
|
|
101
|
-
this._textarea.style.height = height;
|
|
102
|
-
};
|
|
103
|
-
this.handleChange = event => {
|
|
104
|
-
const _this$props = this.props,
|
|
105
|
-
onChange = _this$props.onChange,
|
|
106
|
-
value = _this$props.value,
|
|
107
|
-
disabled = _this$props.disabled,
|
|
108
|
-
readOnly = _this$props.readOnly;
|
|
109
|
-
if (disabled || readOnly) {
|
|
110
|
-
event.preventDefault();
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
if (typeof value === 'undefined') {
|
|
114
|
-
// if uncontrolled
|
|
115
|
-
this.autoGrow();
|
|
116
|
-
}
|
|
117
|
-
if (typeof onChange === 'function') {
|
|
118
|
-
onChange(event);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
this.handleContainerRef = node => {
|
|
122
|
-
this._container = node;
|
|
123
|
-
};
|
|
124
73
|
this._defaultId = props.deterministicId();
|
|
125
74
|
|
|
126
75
|
//mock ResizeObserver for ssr
|
|
@@ -139,7 +88,6 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
139
88
|
}
|
|
140
89
|
}
|
|
141
90
|
componentDidMount() {
|
|
142
|
-
var _this$props$makeStyle, _this$props2;
|
|
143
91
|
this.myObserver = new ResizeObserver(entries => {
|
|
144
92
|
for (const entry of entries) {
|
|
145
93
|
if (this._highlightRef) {
|
|
@@ -157,12 +105,11 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
157
105
|
}
|
|
158
106
|
});
|
|
159
107
|
this.autoGrow();
|
|
160
|
-
|
|
108
|
+
this.props.makeStyles?.();
|
|
161
109
|
}
|
|
162
110
|
componentDidUpdate() {
|
|
163
|
-
var _this$props$makeStyle2, _this$props3;
|
|
164
111
|
this.autoGrow();
|
|
165
|
-
|
|
112
|
+
this.props.makeStyles?.();
|
|
166
113
|
}
|
|
167
114
|
componentWillUnmount() {
|
|
168
115
|
if (this._listener) {
|
|
@@ -181,6 +128,16 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
181
128
|
this.myObserver.disconnect();
|
|
182
129
|
}
|
|
183
130
|
}
|
|
131
|
+
_textareaResize = () => {
|
|
132
|
+
const textareaHeight = this._textarea.style.height;
|
|
133
|
+
if (textareaHeight !== '' && textareaHeight !== this._height) {
|
|
134
|
+
this._manuallyResized = true;
|
|
135
|
+
this._textarea.style.overflowY = 'auto';
|
|
136
|
+
|
|
137
|
+
// update container minHeight to ensure focus ring always wraps input
|
|
138
|
+
this._container.style.minHeight = textareaHeight;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
184
141
|
autoGrow() {
|
|
185
142
|
if (this.props.autoGrow) {
|
|
186
143
|
if (!this._debounced) {
|
|
@@ -193,11 +150,14 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
193
150
|
this._listener = addEventListener(window, 'resize', this._debounced);
|
|
194
151
|
}
|
|
195
152
|
if (this._textarea && !this._textareaResizeListener) {
|
|
196
|
-
const
|
|
197
|
-
origHeight
|
|
153
|
+
const {
|
|
154
|
+
height: origHeight
|
|
155
|
+
} = getBoundingClientRect(this._textarea);
|
|
198
156
|
this._textareaResizeListener = new ResizeObserver(entries => {
|
|
199
157
|
for (const entry of entries) {
|
|
200
|
-
const
|
|
158
|
+
const {
|
|
159
|
+
height
|
|
160
|
+
} = entry.contentRect;
|
|
201
161
|
if (origHeight !== height) {
|
|
202
162
|
this._textareaResize();
|
|
203
163
|
}
|
|
@@ -208,9 +168,65 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
208
168
|
this._request = requestAnimationFrame(this.grow);
|
|
209
169
|
}
|
|
210
170
|
}
|
|
171
|
+
grow = () => {
|
|
172
|
+
if (!this._textarea || this._manuallyResized) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const offset = this._textarea.offsetHeight - this._textarea.clientHeight;
|
|
176
|
+
let height = '';
|
|
177
|
+
|
|
178
|
+
// Notes:
|
|
179
|
+
// 1. height has to be reset to `auto` every time this method runs, or scrollHeight will not reset
|
|
180
|
+
// 2. `this._textarea.scrollHeight` will not reset if assigned to a variable; it needs to be written out each time
|
|
181
|
+
this._textarea.style.height = 'auto';
|
|
182
|
+
this._textarea.style.overflowY = 'hidden'; // hide scrollbars for autoGrow textareas
|
|
183
|
+
height = this._textarea.scrollHeight + offset + 'px';
|
|
184
|
+
const maxHeight = this.props.maxHeight ? px(this.props.maxHeight, this._container) : undefined;
|
|
185
|
+
if (this.props.maxHeight && maxHeight !== undefined && this._textarea.scrollHeight > maxHeight) {
|
|
186
|
+
this._textarea.style.overflowY = 'auto'; // add scroll if scrollHeight exceeds maxHeight in pixels
|
|
187
|
+
} else if (this.props.height) {
|
|
188
|
+
if (this._textarea.value === '') {
|
|
189
|
+
height = this.props.height;
|
|
190
|
+
} else if (px(this.props.height, this._container) > this._textarea.scrollHeight) {
|
|
191
|
+
this._textarea.style.overflowY = 'auto'; // add scroll if scrollHeight exceeds height in pixels
|
|
192
|
+
height = this.props.height;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// preserve container height to prevent scroll jumping on long textareas,
|
|
197
|
+
// but make sure container doesn't exceed maxHeight prop
|
|
198
|
+
const heightExceedsMax = maxHeight !== undefined && px(height) > maxHeight;
|
|
199
|
+
if (!heightExceedsMax) {
|
|
200
|
+
this._container.style.minHeight = height;
|
|
201
|
+
}
|
|
202
|
+
this._height = height;
|
|
203
|
+
this._textarea.style.height = height;
|
|
204
|
+
};
|
|
211
205
|
focus() {
|
|
212
206
|
this._textarea.focus();
|
|
213
207
|
}
|
|
208
|
+
handleChange = event => {
|
|
209
|
+
const {
|
|
210
|
+
onChange,
|
|
211
|
+
value,
|
|
212
|
+
disabled,
|
|
213
|
+
readOnly
|
|
214
|
+
} = this.props;
|
|
215
|
+
if (disabled || readOnly) {
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (typeof value === 'undefined') {
|
|
220
|
+
// if uncontrolled
|
|
221
|
+
this.autoGrow();
|
|
222
|
+
}
|
|
223
|
+
if (typeof onChange === 'function') {
|
|
224
|
+
onChange(event);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
handleContainerRef = node => {
|
|
228
|
+
this._container = node;
|
|
229
|
+
};
|
|
214
230
|
get minHeight() {
|
|
215
231
|
return this._textarea.style.minHeight;
|
|
216
232
|
}
|
|
@@ -229,27 +245,27 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
229
245
|
return this._textarea.value;
|
|
230
246
|
}
|
|
231
247
|
render() {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
+
const {
|
|
249
|
+
autoGrow,
|
|
250
|
+
placeholder,
|
|
251
|
+
value,
|
|
252
|
+
defaultValue,
|
|
253
|
+
disabled,
|
|
254
|
+
readOnly,
|
|
255
|
+
required,
|
|
256
|
+
width,
|
|
257
|
+
height,
|
|
258
|
+
maxHeight,
|
|
259
|
+
textareaRef,
|
|
260
|
+
resize,
|
|
261
|
+
styles,
|
|
262
|
+
margin
|
|
263
|
+
} = this.props;
|
|
248
264
|
const props = omitProps(this.props, TextArea.allowedProps);
|
|
249
265
|
const style = {
|
|
250
266
|
width,
|
|
251
267
|
resize,
|
|
252
|
-
height: !autoGrow ? height :
|
|
268
|
+
height: !autoGrow ? height : undefined,
|
|
253
269
|
maxHeight
|
|
254
270
|
};
|
|
255
271
|
const textarea = _jsx("textarea", {
|
|
@@ -259,8 +275,7 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
259
275
|
placeholder: placeholder,
|
|
260
276
|
ref: textarea => {
|
|
261
277
|
if (textarea) {
|
|
262
|
-
|
|
263
|
-
(_this$myObserver = this.myObserver) === null || _this$myObserver === void 0 ? void 0 : _this$myObserver.observe(textarea);
|
|
278
|
+
this.myObserver?.observe(textarea);
|
|
264
279
|
}
|
|
265
280
|
this._textarea = textarea;
|
|
266
281
|
if (typeof textareaRef === 'function') {
|
|
@@ -271,14 +286,14 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
271
286
|
id: this.id,
|
|
272
287
|
required: required,
|
|
273
288
|
"aria-required": required,
|
|
274
|
-
"aria-invalid": this.invalid ? 'true' :
|
|
289
|
+
"aria-invalid": this.invalid ? 'true' : undefined,
|
|
275
290
|
disabled: disabled || readOnly,
|
|
276
|
-
css:
|
|
291
|
+
css: this.props.styles?.textArea,
|
|
277
292
|
onChange: this.handleChange
|
|
278
293
|
});
|
|
279
294
|
const label = hasVisibleChildren(this.props.label) ? _jsxs(Fragment, {
|
|
280
295
|
children: [this.props.label, required && _jsxs("span", {
|
|
281
|
-
css: this.invalid ? styles
|
|
296
|
+
css: this.invalid ? styles?.requiredInvalid : {},
|
|
282
297
|
"aria-hidden": true,
|
|
283
298
|
children: [' ', "*"]
|
|
284
299
|
})]
|
|
@@ -294,14 +309,14 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
294
309
|
margin: margin,
|
|
295
310
|
"data-cid": "TextArea",
|
|
296
311
|
children: _jsxs("div", {
|
|
297
|
-
css:
|
|
312
|
+
css: this.props.styles?.textAreaLayout,
|
|
298
313
|
style: {
|
|
299
314
|
width,
|
|
300
315
|
maxHeight
|
|
301
316
|
},
|
|
302
317
|
ref: this.handleContainerRef,
|
|
303
318
|
children: [textarea, !disabled && !readOnly ? _jsx("span", {
|
|
304
|
-
css:
|
|
319
|
+
css: this.props.styles?.textAreaOutline,
|
|
305
320
|
"aria-hidden": "true",
|
|
306
321
|
ref: e => {
|
|
307
322
|
this._highlightRef = e;
|
|
@@ -310,16 +325,6 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
310
325
|
})
|
|
311
326
|
});
|
|
312
327
|
}
|
|
313
|
-
}
|
|
314
|
-
size: 'medium',
|
|
315
|
-
autoGrow: true,
|
|
316
|
-
resize: 'none',
|
|
317
|
-
inline: false,
|
|
318
|
-
messages: [],
|
|
319
|
-
disabled: false,
|
|
320
|
-
readOnly: false,
|
|
321
|
-
layout: 'stacked',
|
|
322
|
-
required: false
|
|
323
|
-
}, _TextArea)) || _class) || _class);
|
|
328
|
+
}) || _class) || _class);
|
|
324
329
|
export default TextArea;
|
|
325
330
|
export { TextArea };
|
package/es/TextArea/v1/styles.js
CHANGED
|
@@ -33,8 +33,10 @@
|
|
|
33
33
|
* @return {Object} The final style object, which will be used in the component
|
|
34
34
|
*/
|
|
35
35
|
const generateStyle = (componentTheme, props) => {
|
|
36
|
-
const
|
|
37
|
-
|
|
36
|
+
const {
|
|
37
|
+
disabled,
|
|
38
|
+
size
|
|
39
|
+
} = props;
|
|
38
40
|
const fontSizeVariants = {
|
|
39
41
|
small: {
|
|
40
42
|
fontSize: componentTheme.smallFontSize
|
package/es/TextArea/v1/theme.js
CHANGED
|
@@ -28,13 +28,14 @@
|
|
|
28
28
|
* @return {Object} The final theme object with the overrides and component variables
|
|
29
29
|
*/
|
|
30
30
|
const generateComponentTheme = theme => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
typography
|
|
34
|
-
borders
|
|
35
|
-
spacing
|
|
36
|
-
forms
|
|
37
|
-
themeName
|
|
31
|
+
const {
|
|
32
|
+
colors,
|
|
33
|
+
typography,
|
|
34
|
+
borders,
|
|
35
|
+
spacing,
|
|
36
|
+
forms,
|
|
37
|
+
key: themeName
|
|
38
|
+
} = theme;
|
|
38
39
|
const themeSpecificStyle = {
|
|
39
40
|
canvas: {
|
|
40
41
|
color: theme['ic-brand-font-color-dark'],
|
|
@@ -42,31 +43,31 @@ const generateComponentTheme = theme => {
|
|
|
42
43
|
}
|
|
43
44
|
};
|
|
44
45
|
const componentVariables = {
|
|
45
|
-
fontFamily: typography
|
|
46
|
-
fontWeight: typography
|
|
47
|
-
color: colors
|
|
48
|
-
background: colors
|
|
49
|
-
requiredInvalidColor: colors
|
|
50
|
-
borderWidth: borders
|
|
51
|
-
borderStyle: borders
|
|
52
|
-
borderTopColor: colors
|
|
53
|
-
borderRightColor: colors
|
|
54
|
-
borderBottomColor: colors
|
|
55
|
-
borderLeftColor: colors
|
|
56
|
-
borderRadius: borders
|
|
57
|
-
padding: spacing
|
|
58
|
-
focusOutlineColor: colors
|
|
59
|
-
focusOutlineWidth: borders
|
|
60
|
-
focusOutlineStyle: borders
|
|
61
|
-
errorBorderColor: colors
|
|
62
|
-
errorOutlineColor: colors
|
|
63
|
-
placeholderColor: colors
|
|
64
|
-
smallFontSize: typography
|
|
65
|
-
smallHeight: forms
|
|
66
|
-
mediumFontSize: typography
|
|
67
|
-
mediumHeight: forms
|
|
68
|
-
largeFontSize: typography
|
|
69
|
-
largeHeight: forms
|
|
46
|
+
fontFamily: typography?.fontFamily,
|
|
47
|
+
fontWeight: typography?.fontWeightNormal,
|
|
48
|
+
color: colors?.contrasts?.grey125125,
|
|
49
|
+
background: colors?.contrasts?.white1010,
|
|
50
|
+
requiredInvalidColor: colors?.contrasts?.red5782,
|
|
51
|
+
borderWidth: borders?.widthSmall,
|
|
52
|
+
borderStyle: borders?.style,
|
|
53
|
+
borderTopColor: colors?.contrasts?.grey3045,
|
|
54
|
+
borderRightColor: colors?.contrasts?.grey3045,
|
|
55
|
+
borderBottomColor: colors?.contrasts?.grey3045,
|
|
56
|
+
borderLeftColor: colors?.contrasts?.grey3045,
|
|
57
|
+
borderRadius: borders?.radiusMedium,
|
|
58
|
+
padding: spacing?.small,
|
|
59
|
+
focusOutlineColor: colors?.contrasts?.blue4570,
|
|
60
|
+
focusOutlineWidth: borders?.widthMedium,
|
|
61
|
+
focusOutlineStyle: borders?.style,
|
|
62
|
+
errorBorderColor: colors?.contrasts?.red4570,
|
|
63
|
+
errorOutlineColor: colors?.contrasts?.red4570,
|
|
64
|
+
placeholderColor: colors?.contrasts?.grey4570,
|
|
65
|
+
smallFontSize: typography?.fontSizeSmall,
|
|
66
|
+
smallHeight: forms?.inputHeightSmall,
|
|
67
|
+
mediumFontSize: typography?.fontSizeMedium,
|
|
68
|
+
mediumHeight: forms?.inputHeightMedium,
|
|
69
|
+
largeFontSize: typography?.fontSizeLarge,
|
|
70
|
+
largeHeight: forms?.inputHeightLarge
|
|
70
71
|
};
|
|
71
72
|
return {
|
|
72
73
|
...componentVariables,
|
package/es/TextArea/v2/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
-
const _excluded = ["size", "autoGrow", "resize", "inline", "messages", "disabled", "readOnly", "layout", "required", "placeholder", "value", "defaultValue", "width", "height", "maxHeight", "textareaRef", "margin", "label", "onChange", "id", "themeOverride"];
|
|
3
1
|
/*
|
|
4
2
|
* The MIT License (MIT)
|
|
5
3
|
*
|
|
@@ -39,37 +37,30 @@ category: components
|
|
|
39
37
|
---
|
|
40
38
|
**/
|
|
41
39
|
const TextArea = /*#__PURE__*/forwardRef((props, ref) => {
|
|
42
|
-
const
|
|
43
|
-
size =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
textareaRef = props.textareaRef,
|
|
67
|
-
margin = props.margin,
|
|
68
|
-
label = props.label,
|
|
69
|
-
onChange = props.onChange,
|
|
70
|
-
propId = props.id,
|
|
71
|
-
themeOverride = props.themeOverride,
|
|
72
|
-
rest = _objectWithoutProperties(props, _excluded);
|
|
40
|
+
const {
|
|
41
|
+
size = 'medium',
|
|
42
|
+
autoGrow = true,
|
|
43
|
+
resize = 'none',
|
|
44
|
+
inline = false,
|
|
45
|
+
messages = [],
|
|
46
|
+
disabled = false,
|
|
47
|
+
readOnly = false,
|
|
48
|
+
layout = 'stacked',
|
|
49
|
+
required = false,
|
|
50
|
+
placeholder,
|
|
51
|
+
value,
|
|
52
|
+
defaultValue,
|
|
53
|
+
width,
|
|
54
|
+
height,
|
|
55
|
+
maxHeight,
|
|
56
|
+
textareaRef,
|
|
57
|
+
margin,
|
|
58
|
+
label,
|
|
59
|
+
onChange,
|
|
60
|
+
id: propId,
|
|
61
|
+
themeOverride,
|
|
62
|
+
...rest
|
|
63
|
+
} = props;
|
|
73
64
|
|
|
74
65
|
// Use deterministic ID
|
|
75
66
|
const instanceCounterMap = useContext(DeterministicIdContext);
|
|
@@ -88,16 +79,17 @@ const TextArea = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
88
79
|
const formFieldRef = useRef(null);
|
|
89
80
|
|
|
90
81
|
// Compute invalid state
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
82
|
+
const {
|
|
83
|
+
isInvalid,
|
|
84
|
+
isSuccess
|
|
85
|
+
} = useMemo(() => {
|
|
86
|
+
const isInvalid = messages && messages.findIndex(message => message.type === 'error' || message.type === 'newError') >= 0;
|
|
87
|
+
const isSuccess = messages && messages.findIndex(message => message.type === 'success') >= 0;
|
|
88
|
+
return {
|
|
89
|
+
isInvalid,
|
|
90
|
+
isSuccess
|
|
91
|
+
};
|
|
92
|
+
}, [messages]);
|
|
101
93
|
|
|
102
94
|
// Use styles
|
|
103
95
|
const styles = useStyle({
|
|
@@ -145,8 +137,8 @@ const TextArea = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
145
137
|
_textarea.current.style.height = 'auto';
|
|
146
138
|
_textarea.current.style.overflowY = 'hidden'; // hide scrollbars for autoGrow textareas
|
|
147
139
|
heightValue = _textarea.current.scrollHeight + offset + 'px';
|
|
148
|
-
const maxHeightPx = maxHeight ? px(maxHeight, _container.current) :
|
|
149
|
-
if (maxHeight && maxHeightPx !==
|
|
140
|
+
const maxHeightPx = maxHeight ? px(maxHeight, _container.current) : undefined;
|
|
141
|
+
if (maxHeight && maxHeightPx !== undefined && _textarea.current.scrollHeight > maxHeightPx) {
|
|
150
142
|
_textarea.current.style.overflowY = 'auto'; // add scroll if scrollHeight exceeds maxHeight in pixels
|
|
151
143
|
} else if (height) {
|
|
152
144
|
if (_textarea.current.value === '') {
|
|
@@ -159,7 +151,7 @@ const TextArea = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
159
151
|
|
|
160
152
|
// preserve container height to prevent scroll jumping on long textareas,
|
|
161
153
|
// but make sure container doesn't exceed maxHeight prop
|
|
162
|
-
const heightExceedsMax = maxHeightPx !==
|
|
154
|
+
const heightExceedsMax = maxHeightPx !== undefined && px(heightValue) > maxHeightPx;
|
|
163
155
|
if (!heightExceedsMax && _container.current) {
|
|
164
156
|
_container.current.style.minHeight = heightValue;
|
|
165
157
|
}
|
|
@@ -195,11 +187,14 @@ const TextArea = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
195
187
|
_listener.current = addEventListener(window, 'resize', _debounced.current);
|
|
196
188
|
}
|
|
197
189
|
if (_textarea.current && !_textareaResizeListener.current) {
|
|
198
|
-
const
|
|
199
|
-
origHeight
|
|
190
|
+
const {
|
|
191
|
+
height: origHeight
|
|
192
|
+
} = getBoundingClientRect(_textarea.current);
|
|
200
193
|
_textareaResizeListener.current = new ResizeObserver(entries => {
|
|
201
194
|
for (const entry of entries) {
|
|
202
|
-
const
|
|
195
|
+
const {
|
|
196
|
+
height: entryHeight
|
|
197
|
+
} = entry.contentRect;
|
|
203
198
|
if (origHeight !== entryHeight) {
|
|
204
199
|
_textareaResize();
|
|
205
200
|
}
|
|
@@ -248,11 +243,14 @@ const TextArea = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
248
243
|
_listener.current = addEventListener(window, 'resize', _debounced.current);
|
|
249
244
|
}
|
|
250
245
|
if (_textarea.current && !_textareaResizeListener.current) {
|
|
251
|
-
const
|
|
252
|
-
origHeight
|
|
246
|
+
const {
|
|
247
|
+
height: origHeight
|
|
248
|
+
} = getBoundingClientRect(_textarea.current);
|
|
253
249
|
_textareaResizeListener.current = new ResizeObserver(entries => {
|
|
254
250
|
for (const entry of entries) {
|
|
255
|
-
const
|
|
251
|
+
const {
|
|
252
|
+
height: entryHeight
|
|
253
|
+
} = entry.contentRect;
|
|
256
254
|
if (origHeight !== entryHeight) {
|
|
257
255
|
_textareaResize();
|
|
258
256
|
}
|
|
@@ -271,16 +269,13 @@ const TextArea = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
271
269
|
// Expose API through ref using useImperativeHandle
|
|
272
270
|
useImperativeHandle(ref, () => ({
|
|
273
271
|
focus: () => {
|
|
274
|
-
|
|
275
|
-
(_textarea$current = _textarea.current) === null || _textarea$current === void 0 ? void 0 : _textarea$current.focus();
|
|
272
|
+
_textarea.current?.focus();
|
|
276
273
|
},
|
|
277
274
|
get value() {
|
|
278
|
-
|
|
279
|
-
return ((_textarea$current2 = _textarea.current) === null || _textarea$current2 === void 0 ? void 0 : _textarea$current2.value) || '';
|
|
275
|
+
return _textarea.current?.value || '';
|
|
280
276
|
},
|
|
281
277
|
get minHeight() {
|
|
282
|
-
|
|
283
|
-
return ((_textarea$current3 = _textarea.current) === null || _textarea$current3 === void 0 ? void 0 : _textarea$current3.style.minHeight) || '';
|
|
278
|
+
return _textarea.current?.style.minHeight || '';
|
|
284
279
|
},
|
|
285
280
|
get focused() {
|
|
286
281
|
return isActiveElement(_textarea.current);
|
|
@@ -296,7 +291,7 @@ const TextArea = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
296
291
|
const style = {
|
|
297
292
|
width,
|
|
298
293
|
resize,
|
|
299
|
-
height: !autoGrow ? height :
|
|
294
|
+
height: !autoGrow ? height : undefined,
|
|
300
295
|
maxHeight
|
|
301
296
|
};
|
|
302
297
|
const textarea = _jsx("textarea", {
|
|
@@ -314,10 +309,10 @@ const TextArea = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
314
309
|
id: id,
|
|
315
310
|
required: required,
|
|
316
311
|
"aria-required": required,
|
|
317
|
-
"aria-invalid": isInvalid ? 'true' :
|
|
312
|
+
"aria-invalid": isInvalid ? 'true' : undefined,
|
|
318
313
|
disabled: disabled,
|
|
319
314
|
readOnly: readOnly,
|
|
320
|
-
css: styles
|
|
315
|
+
css: styles?.textArea,
|
|
321
316
|
onChange: handleChange
|
|
322
317
|
});
|
|
323
318
|
return _jsx(FormField, {
|
|
@@ -334,7 +329,7 @@ const TextArea = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
334
329
|
readOnly: readOnly,
|
|
335
330
|
"data-cid": "TextArea",
|
|
336
331
|
children: _jsx("div", {
|
|
337
|
-
css: styles
|
|
332
|
+
css: styles?.textAreaLayout,
|
|
338
333
|
style: {
|
|
339
334
|
width,
|
|
340
335
|
maxHeight
|