@instructure/ui-text-area 8.33.1-snapshot-1 → 8.33.2-snapshot-5
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 +4 -8
- package/es/TextArea/TextAreaLocator.js +3 -1
- package/es/TextArea/index.js +26 -65
- package/es/TextArea/locator.js +1 -0
- package/es/TextArea/props.js +1 -0
- package/es/TextArea/styles.js +1 -2
- package/es/TextArea/theme.js +7 -7
- package/lib/TextArea/TextAreaLocator.js +1 -3
- package/lib/TextArea/index.js +25 -82
- package/lib/TextArea/locator.js +0 -2
- package/lib/TextArea/props.js +1 -5
- package/lib/TextArea/styles.js +1 -3
- package/lib/TextArea/theme.js +7 -8
- package/lib/index.js +0 -1
- package/package.json +16 -16
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
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
|
-
## [8.33.
|
|
6
|
+
## [8.33.2-snapshot-5](https://github.com/instructure/instructure-ui/compare/v8.33.1...v8.33.2-snapshot-5) (2023-01-23)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-text-area
|
|
9
9
|
|
|
@@ -11,22 +11,18 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
## [8.33.1](https://github.com/instructure/instructure-ui/compare/v8.33.0...v8.33.1) (2023-01-06)
|
|
15
15
|
|
|
16
16
|
**Note:** Version bump only for package @instructure/ui-text-area
|
|
17
17
|
|
|
18
|
+
# [8.33.0](https://github.com/instructure/instructure-ui/compare/v8.32.1...v8.33.0) (2023-01-04)
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
**Note:** Version bump only for package @instructure/ui-text-area
|
|
21
21
|
|
|
22
22
|
## [8.32.1](https://github.com/instructure/instructure-ui/compare/v8.30.0...v8.32.1) (2022-12-01)
|
|
23
23
|
|
|
24
24
|
**Note:** Version bump only for package @instructure/ui-text-area
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
26
|
# [8.32.0](https://github.com/instructure/instructure-ui/compare/v8.31.0...v8.32.0) (2022-11-23)
|
|
31
27
|
|
|
32
28
|
**Note:** Version bump only for package @instructure/ui-text-area
|
|
@@ -21,9 +21,11 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import { locator } from '@instructure/ui-test-locator';
|
|
25
|
-
import { TextArea } from './index';
|
|
26
|
+
import { TextArea } from './index';
|
|
26
27
|
|
|
28
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
|
|
27
29
|
export const TextAreaLocator = locator(TextArea.selector, {
|
|
28
30
|
findInput: function () {
|
|
29
31
|
return locator('textarea').find(...arguments);
|
package/es/TextArea/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
var _dec, _dec2, _dec3, _class, _class2;
|
|
2
|
-
|
|
3
2
|
/*
|
|
4
3
|
* The MIT License (MIT)
|
|
5
4
|
*
|
|
@@ -36,13 +35,13 @@ import { omitProps, pickProps, withDeterministicId } from '@instructure/ui-react
|
|
|
36
35
|
import generateStyle from './styles';
|
|
37
36
|
import generateComponentTheme from './theme';
|
|
38
37
|
import { allowedProps, propTypes } from './props';
|
|
38
|
+
|
|
39
39
|
/**
|
|
40
40
|
---
|
|
41
41
|
category: components
|
|
42
42
|
---
|
|
43
43
|
@tsProps
|
|
44
44
|
**/
|
|
45
|
-
|
|
46
45
|
let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec3 = testable(), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = class TextArea extends Component {
|
|
47
46
|
constructor(props) {
|
|
48
47
|
super(props);
|
|
@@ -56,34 +55,30 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
56
55
|
this._height = void 0;
|
|
57
56
|
this._manuallyResized = false;
|
|
58
57
|
this.ref = null;
|
|
59
|
-
|
|
60
58
|
this._textareaResize = () => {
|
|
61
59
|
const textareaHeight = this._textarea.style.height;
|
|
62
|
-
|
|
63
60
|
if (textareaHeight !== '' && textareaHeight !== this._height) {
|
|
64
61
|
this._manuallyResized = true;
|
|
65
|
-
this._textarea.style.overflowY = 'auto';
|
|
62
|
+
this._textarea.style.overflowY = 'auto';
|
|
66
63
|
|
|
64
|
+
// update container minHeight to ensure focus ring always wraps input
|
|
67
65
|
this._container.style.minHeight = textareaHeight;
|
|
68
66
|
}
|
|
69
67
|
};
|
|
70
|
-
|
|
71
68
|
this.grow = () => {
|
|
72
69
|
if (!this._textarea || this._manuallyResized) {
|
|
73
70
|
return;
|
|
74
71
|
}
|
|
75
|
-
|
|
76
72
|
const offset = this._textarea.offsetHeight - this._textarea.clientHeight;
|
|
77
|
-
let height = '';
|
|
73
|
+
let height = '';
|
|
74
|
+
|
|
75
|
+
// Notes:
|
|
78
76
|
// 1. height has to be reset to `auto` every time this method runs, or scrollHeight will not reset
|
|
79
77
|
// 2. `this._textarea.scrollHeight` will not reset if assigned to a variable; it needs to be written out each time
|
|
80
|
-
|
|
81
78
|
this._textarea.style.height = 'auto';
|
|
82
79
|
this._textarea.style.overflowY = 'hidden'; // hide scrollbars for autoGrow textareas
|
|
83
|
-
|
|
84
80
|
height = this._textarea.scrollHeight + offset + 'px';
|
|
85
81
|
const maxHeight = this.props.maxHeight ? px(this.props.maxHeight, this._container) : void 0;
|
|
86
|
-
|
|
87
82
|
if (this.props.maxHeight && maxHeight !== void 0 && this._textarea.scrollHeight > maxHeight) {
|
|
88
83
|
this._textarea.style.overflowY = 'auto'; // add scroll if scrollHeight exceeds maxHeight in pixels
|
|
89
84
|
} else if (this.props.height) {
|
|
@@ -91,84 +86,66 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
91
86
|
height = this.props.height;
|
|
92
87
|
} else if (px(this.props.height, this._container) > this._textarea.scrollHeight) {
|
|
93
88
|
this._textarea.style.overflowY = 'auto'; // add scroll if scrollHeight exceeds height in pixels
|
|
94
|
-
|
|
95
89
|
height = this.props.height;
|
|
96
90
|
}
|
|
97
|
-
}
|
|
98
|
-
// but make sure container doesn't exceed maxHeight prop
|
|
99
|
-
|
|
91
|
+
}
|
|
100
92
|
|
|
93
|
+
// preserve container height to prevent scroll jumping on long textareas,
|
|
94
|
+
// but make sure container doesn't exceed maxHeight prop
|
|
101
95
|
const heightExceedsMax = maxHeight !== void 0 && px(height) > maxHeight;
|
|
102
|
-
|
|
103
96
|
if (!heightExceedsMax) {
|
|
104
97
|
this._container.style.minHeight = height;
|
|
105
98
|
}
|
|
106
|
-
|
|
107
99
|
this._height = height;
|
|
108
100
|
this._textarea.style.height = height;
|
|
109
101
|
};
|
|
110
|
-
|
|
111
102
|
this.handleChange = event => {
|
|
112
103
|
const _this$props = this.props,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
104
|
+
onChange = _this$props.onChange,
|
|
105
|
+
value = _this$props.value,
|
|
106
|
+
disabled = _this$props.disabled,
|
|
107
|
+
readOnly = _this$props.readOnly;
|
|
118
108
|
if (disabled || readOnly) {
|
|
119
109
|
event.preventDefault();
|
|
120
110
|
return;
|
|
121
111
|
}
|
|
122
|
-
|
|
123
112
|
if (typeof value === 'undefined') {
|
|
124
113
|
// if uncontrolled
|
|
125
114
|
this.autoGrow();
|
|
126
115
|
}
|
|
127
|
-
|
|
128
116
|
if (typeof onChange === 'function') {
|
|
129
117
|
onChange(event);
|
|
130
118
|
}
|
|
131
119
|
};
|
|
132
|
-
|
|
133
120
|
this.handleContainerRef = node => {
|
|
134
121
|
this._container = node;
|
|
135
122
|
};
|
|
136
|
-
|
|
137
123
|
this._defaultId = props.deterministicId();
|
|
138
124
|
}
|
|
139
|
-
|
|
140
125
|
componentDidMount() {
|
|
141
126
|
var _this$props$makeStyle, _this$props2;
|
|
142
|
-
|
|
143
127
|
this.autoGrow();
|
|
144
128
|
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
|
|
145
129
|
}
|
|
146
|
-
|
|
147
130
|
componentDidUpdate() {
|
|
148
131
|
var _this$props$makeStyle2, _this$props3;
|
|
149
|
-
|
|
150
132
|
this.autoGrow();
|
|
151
133
|
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
|
|
152
134
|
}
|
|
153
|
-
|
|
154
135
|
componentWillUnmount() {
|
|
155
136
|
if (this._listener) {
|
|
156
137
|
this._listener.remove();
|
|
157
138
|
}
|
|
158
|
-
|
|
159
139
|
if (this._textareaResizeListener) {
|
|
160
140
|
this._textareaResizeListener.disconnect();
|
|
161
141
|
}
|
|
162
|
-
|
|
163
142
|
if (this._request) {
|
|
164
143
|
this._request.cancel();
|
|
165
144
|
}
|
|
166
|
-
|
|
167
145
|
if (this._debounced) {
|
|
168
146
|
this._debounced.cancel();
|
|
169
147
|
}
|
|
170
148
|
}
|
|
171
|
-
|
|
172
149
|
autoGrow() {
|
|
173
150
|
if (this.props.autoGrow) {
|
|
174
151
|
if (!this._debounced) {
|
|
@@ -177,74 +154,60 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
177
154
|
trailing: true
|
|
178
155
|
});
|
|
179
156
|
}
|
|
180
|
-
|
|
181
157
|
if (!this._listener) {
|
|
182
158
|
this._listener = addEventListener(window, 'resize', this._debounced);
|
|
183
159
|
}
|
|
184
|
-
|
|
185
160
|
if (this._textarea && !this._textareaResizeListener) {
|
|
186
161
|
const _getBoundingClientRec = getBoundingClientRect(this._textarea),
|
|
187
|
-
|
|
188
|
-
|
|
162
|
+
origHeight = _getBoundingClientRec.height;
|
|
189
163
|
this._textareaResizeListener = new ResizeObserver(entries => {
|
|
190
164
|
for (const entry of entries) {
|
|
191
165
|
const height = entry.contentRect.height;
|
|
192
|
-
|
|
193
166
|
if (origHeight !== height) {
|
|
194
167
|
this._textareaResize();
|
|
195
168
|
}
|
|
196
169
|
}
|
|
197
170
|
});
|
|
198
|
-
|
|
199
171
|
this._textareaResizeListener.observe(this._textarea);
|
|
200
172
|
}
|
|
201
|
-
|
|
202
173
|
this._request = requestAnimationFrame(this.grow);
|
|
203
174
|
}
|
|
204
175
|
}
|
|
205
|
-
|
|
206
176
|
focus() {
|
|
207
177
|
this._textarea.focus();
|
|
208
178
|
}
|
|
209
|
-
|
|
210
179
|
get minHeight() {
|
|
211
180
|
return this._textarea.style.minHeight;
|
|
212
181
|
}
|
|
213
|
-
|
|
214
182
|
get invalid() {
|
|
215
183
|
return this.props.messages && this.props.messages.findIndex(message => {
|
|
216
184
|
return message.type === 'error';
|
|
217
185
|
}) >= 0;
|
|
218
186
|
}
|
|
219
|
-
|
|
220
187
|
get id() {
|
|
221
188
|
return this.props.id || this._defaultId;
|
|
222
189
|
}
|
|
223
|
-
|
|
224
190
|
get focused() {
|
|
225
191
|
return isActiveElement(this._textarea);
|
|
226
192
|
}
|
|
227
|
-
|
|
228
193
|
get value() {
|
|
229
194
|
return this._textarea.value;
|
|
230
195
|
}
|
|
231
|
-
|
|
232
196
|
render() {
|
|
233
197
|
var _this$props$styles, _this$props$styles2, _this$props$styles3;
|
|
234
|
-
|
|
235
198
|
const _this$props4 = this.props,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
199
|
+
autoGrow = _this$props4.autoGrow,
|
|
200
|
+
placeholder = _this$props4.placeholder,
|
|
201
|
+
value = _this$props4.value,
|
|
202
|
+
defaultValue = _this$props4.defaultValue,
|
|
203
|
+
disabled = _this$props4.disabled,
|
|
204
|
+
readOnly = _this$props4.readOnly,
|
|
205
|
+
required = _this$props4.required,
|
|
206
|
+
width = _this$props4.width,
|
|
207
|
+
height = _this$props4.height,
|
|
208
|
+
maxHeight = _this$props4.maxHeight,
|
|
209
|
+
textareaRef = _this$props4.textareaRef,
|
|
210
|
+
resize = _this$props4.resize;
|
|
248
211
|
const props = omitProps(this.props, TextArea.allowedProps);
|
|
249
212
|
const style = {
|
|
250
213
|
width,
|
|
@@ -258,7 +221,6 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
258
221
|
placeholder: placeholder,
|
|
259
222
|
ref: textarea => {
|
|
260
223
|
this._textarea = textarea;
|
|
261
|
-
|
|
262
224
|
if (typeof textareaRef === 'function') {
|
|
263
225
|
textareaRef(textarea);
|
|
264
226
|
}
|
|
@@ -291,7 +253,6 @@ let TextArea = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
291
253
|
"aria-hidden": "true"
|
|
292
254
|
}) : null));
|
|
293
255
|
}
|
|
294
|
-
|
|
295
256
|
}, _class2.displayName = "TextArea", _class2.componentId = 'TextArea', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
|
|
296
257
|
size: 'medium',
|
|
297
258
|
autoGrow: true,
|
package/es/TextArea/locator.js
CHANGED
package/es/TextArea/props.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import PropTypes from 'prop-types';
|
|
25
26
|
import { controllable } from '@instructure/ui-prop-types';
|
|
26
27
|
import { FormPropTypes } from '@instructure/ui-form-field';
|
package/es/TextArea/styles.js
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
*/
|
|
35
35
|
const generateStyle = (componentTheme, props) => {
|
|
36
36
|
const disabled = props.disabled,
|
|
37
|
-
|
|
37
|
+
size = props.size;
|
|
38
38
|
const fontSizeVariants = {
|
|
39
39
|
small: {
|
|
40
40
|
fontSize: componentTheme.smallFontSize
|
|
@@ -113,5 +113,4 @@ const generateStyle = (componentTheme, props) => {
|
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
115
|
};
|
|
116
|
-
|
|
117
116
|
export default generateStyle;
|
package/es/TextArea/theme.js
CHANGED
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
*/
|
|
30
30
|
const generateComponentTheme = theme => {
|
|
31
31
|
const colors = theme.colors,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
typography = theme.typography,
|
|
33
|
+
borders = theme.borders,
|
|
34
|
+
spacing = theme.spacing,
|
|
35
|
+
forms = theme.forms,
|
|
36
|
+
themeName = theme.key;
|
|
37
37
|
const themeSpecificStyle = {
|
|
38
38
|
canvas: {
|
|
39
39
|
color: theme['ic-brand-font-color-dark'],
|
|
@@ -66,9 +66,9 @@ const generateComponentTheme = theme => {
|
|
|
66
66
|
largeFontSize: typography === null || typography === void 0 ? void 0 : typography.fontSizeLarge,
|
|
67
67
|
largeHeight: forms === null || forms === void 0 ? void 0 : forms.inputHeightLarge
|
|
68
68
|
};
|
|
69
|
-
return {
|
|
69
|
+
return {
|
|
70
|
+
...componentVariables,
|
|
70
71
|
...themeSpecificStyle[themeName]
|
|
71
72
|
};
|
|
72
73
|
};
|
|
73
|
-
|
|
74
74
|
export default generateComponentTheme;
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.TextAreaLocator = void 0;
|
|
7
|
-
|
|
8
7
|
var _locator = require("@instructure/ui-test-locator/lib/utils/locator.js");
|
|
9
|
-
|
|
10
8
|
var _index = require("./index");
|
|
11
|
-
|
|
12
9
|
/*
|
|
13
10
|
* The MIT License (MIT)
|
|
14
11
|
*
|
|
@@ -32,6 +29,7 @@ var _index = require("./index");
|
|
|
32
29
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
30
|
* SOFTWARE.
|
|
34
31
|
*/
|
|
32
|
+
|
|
35
33
|
// @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
|
|
36
34
|
const TextAreaLocator = (0, _locator.locator)(_index.TextArea.selector, {
|
|
37
35
|
findInput: function () {
|
package/lib/TextArea/index.js
CHANGED
|
@@ -1,46 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = exports.TextArea = void 0;
|
|
9
|
-
|
|
10
8
|
var _react = require("react");
|
|
11
|
-
|
|
12
9
|
var _FormField = require("@instructure/ui-form-field/lib/FormField");
|
|
13
|
-
|
|
14
10
|
var _addEventListener = require("@instructure/ui-dom-utils/lib/addEventListener.js");
|
|
15
|
-
|
|
16
11
|
var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
|
|
17
|
-
|
|
18
12
|
var _requestAnimationFrame = require("@instructure/ui-dom-utils/lib/requestAnimationFrame.js");
|
|
19
|
-
|
|
20
13
|
var _getBoundingClientRect = require("@instructure/ui-dom-utils/lib/getBoundingClientRect.js");
|
|
21
|
-
|
|
22
14
|
var _debounce = require("@instructure/debounce");
|
|
23
|
-
|
|
24
15
|
var _emotion = require("@instructure/emotion");
|
|
25
|
-
|
|
26
16
|
var _px = require("@instructure/ui-utils/lib/px.js");
|
|
27
|
-
|
|
28
17
|
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
29
|
-
|
|
30
18
|
var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
|
|
31
|
-
|
|
32
19
|
var _pickProps = require("@instructure/ui-react-utils/lib/pickProps.js");
|
|
33
|
-
|
|
34
20
|
var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
|
|
35
|
-
|
|
36
21
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
37
|
-
|
|
38
22
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
39
|
-
|
|
40
23
|
var _props = require("./props");
|
|
41
|
-
|
|
42
24
|
var _dec, _dec2, _dec3, _class, _class2;
|
|
43
|
-
|
|
44
25
|
/**
|
|
45
26
|
---
|
|
46
27
|
category: components
|
|
@@ -60,34 +41,30 @@ let TextArea = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
|
|
|
60
41
|
this._height = void 0;
|
|
61
42
|
this._manuallyResized = false;
|
|
62
43
|
this.ref = null;
|
|
63
|
-
|
|
64
44
|
this._textareaResize = () => {
|
|
65
45
|
const textareaHeight = this._textarea.style.height;
|
|
66
|
-
|
|
67
46
|
if (textareaHeight !== '' && textareaHeight !== this._height) {
|
|
68
47
|
this._manuallyResized = true;
|
|
69
|
-
this._textarea.style.overflowY = 'auto';
|
|
48
|
+
this._textarea.style.overflowY = 'auto';
|
|
70
49
|
|
|
50
|
+
// update container minHeight to ensure focus ring always wraps input
|
|
71
51
|
this._container.style.minHeight = textareaHeight;
|
|
72
52
|
}
|
|
73
53
|
};
|
|
74
|
-
|
|
75
54
|
this.grow = () => {
|
|
76
55
|
if (!this._textarea || this._manuallyResized) {
|
|
77
56
|
return;
|
|
78
57
|
}
|
|
79
|
-
|
|
80
58
|
const offset = this._textarea.offsetHeight - this._textarea.clientHeight;
|
|
81
|
-
let height = '';
|
|
59
|
+
let height = '';
|
|
60
|
+
|
|
61
|
+
// Notes:
|
|
82
62
|
// 1. height has to be reset to `auto` every time this method runs, or scrollHeight will not reset
|
|
83
63
|
// 2. `this._textarea.scrollHeight` will not reset if assigned to a variable; it needs to be written out each time
|
|
84
|
-
|
|
85
64
|
this._textarea.style.height = 'auto';
|
|
86
65
|
this._textarea.style.overflowY = 'hidden'; // hide scrollbars for autoGrow textareas
|
|
87
|
-
|
|
88
66
|
height = this._textarea.scrollHeight + offset + 'px';
|
|
89
67
|
const maxHeight = this.props.maxHeight ? (0, _px.px)(this.props.maxHeight, this._container) : void 0;
|
|
90
|
-
|
|
91
68
|
if (this.props.maxHeight && maxHeight !== void 0 && this._textarea.scrollHeight > maxHeight) {
|
|
92
69
|
this._textarea.style.overflowY = 'auto'; // add scroll if scrollHeight exceeds maxHeight in pixels
|
|
93
70
|
} else if (this.props.height) {
|
|
@@ -95,84 +72,66 @@ let TextArea = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
|
|
|
95
72
|
height = this.props.height;
|
|
96
73
|
} else if ((0, _px.px)(this.props.height, this._container) > this._textarea.scrollHeight) {
|
|
97
74
|
this._textarea.style.overflowY = 'auto'; // add scroll if scrollHeight exceeds height in pixels
|
|
98
|
-
|
|
99
75
|
height = this.props.height;
|
|
100
76
|
}
|
|
101
|
-
}
|
|
102
|
-
// but make sure container doesn't exceed maxHeight prop
|
|
103
|
-
|
|
77
|
+
}
|
|
104
78
|
|
|
79
|
+
// preserve container height to prevent scroll jumping on long textareas,
|
|
80
|
+
// but make sure container doesn't exceed maxHeight prop
|
|
105
81
|
const heightExceedsMax = maxHeight !== void 0 && (0, _px.px)(height) > maxHeight;
|
|
106
|
-
|
|
107
82
|
if (!heightExceedsMax) {
|
|
108
83
|
this._container.style.minHeight = height;
|
|
109
84
|
}
|
|
110
|
-
|
|
111
85
|
this._height = height;
|
|
112
86
|
this._textarea.style.height = height;
|
|
113
87
|
};
|
|
114
|
-
|
|
115
88
|
this.handleChange = event => {
|
|
116
89
|
const _this$props = this.props,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
90
|
+
onChange = _this$props.onChange,
|
|
91
|
+
value = _this$props.value,
|
|
92
|
+
disabled = _this$props.disabled,
|
|
93
|
+
readOnly = _this$props.readOnly;
|
|
122
94
|
if (disabled || readOnly) {
|
|
123
95
|
event.preventDefault();
|
|
124
96
|
return;
|
|
125
97
|
}
|
|
126
|
-
|
|
127
98
|
if (typeof value === 'undefined') {
|
|
128
99
|
// if uncontrolled
|
|
129
100
|
this.autoGrow();
|
|
130
101
|
}
|
|
131
|
-
|
|
132
102
|
if (typeof onChange === 'function') {
|
|
133
103
|
onChange(event);
|
|
134
104
|
}
|
|
135
105
|
};
|
|
136
|
-
|
|
137
106
|
this.handleContainerRef = node => {
|
|
138
107
|
this._container = node;
|
|
139
108
|
};
|
|
140
|
-
|
|
141
109
|
this._defaultId = props.deterministicId();
|
|
142
110
|
}
|
|
143
|
-
|
|
144
111
|
componentDidMount() {
|
|
145
112
|
var _this$props$makeStyle, _this$props2;
|
|
146
|
-
|
|
147
113
|
this.autoGrow();
|
|
148
114
|
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
|
|
149
115
|
}
|
|
150
|
-
|
|
151
116
|
componentDidUpdate() {
|
|
152
117
|
var _this$props$makeStyle2, _this$props3;
|
|
153
|
-
|
|
154
118
|
this.autoGrow();
|
|
155
119
|
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
|
|
156
120
|
}
|
|
157
|
-
|
|
158
121
|
componentWillUnmount() {
|
|
159
122
|
if (this._listener) {
|
|
160
123
|
this._listener.remove();
|
|
161
124
|
}
|
|
162
|
-
|
|
163
125
|
if (this._textareaResizeListener) {
|
|
164
126
|
this._textareaResizeListener.disconnect();
|
|
165
127
|
}
|
|
166
|
-
|
|
167
128
|
if (this._request) {
|
|
168
129
|
this._request.cancel();
|
|
169
130
|
}
|
|
170
|
-
|
|
171
131
|
if (this._debounced) {
|
|
172
132
|
this._debounced.cancel();
|
|
173
133
|
}
|
|
174
134
|
}
|
|
175
|
-
|
|
176
135
|
autoGrow() {
|
|
177
136
|
if (this.props.autoGrow) {
|
|
178
137
|
if (!this._debounced) {
|
|
@@ -181,74 +140,60 @@ let TextArea = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
|
|
|
181
140
|
trailing: true
|
|
182
141
|
});
|
|
183
142
|
}
|
|
184
|
-
|
|
185
143
|
if (!this._listener) {
|
|
186
144
|
this._listener = (0, _addEventListener.addEventListener)(window, 'resize', this._debounced);
|
|
187
145
|
}
|
|
188
|
-
|
|
189
146
|
if (this._textarea && !this._textareaResizeListener) {
|
|
190
147
|
const _getBoundingClientRec = (0, _getBoundingClientRect.getBoundingClientRect)(this._textarea),
|
|
191
|
-
|
|
192
|
-
|
|
148
|
+
origHeight = _getBoundingClientRec.height;
|
|
193
149
|
this._textareaResizeListener = new ResizeObserver(entries => {
|
|
194
150
|
for (const entry of entries) {
|
|
195
151
|
const height = entry.contentRect.height;
|
|
196
|
-
|
|
197
152
|
if (origHeight !== height) {
|
|
198
153
|
this._textareaResize();
|
|
199
154
|
}
|
|
200
155
|
}
|
|
201
156
|
});
|
|
202
|
-
|
|
203
157
|
this._textareaResizeListener.observe(this._textarea);
|
|
204
158
|
}
|
|
205
|
-
|
|
206
159
|
this._request = (0, _requestAnimationFrame.requestAnimationFrame)(this.grow);
|
|
207
160
|
}
|
|
208
161
|
}
|
|
209
|
-
|
|
210
162
|
focus() {
|
|
211
163
|
this._textarea.focus();
|
|
212
164
|
}
|
|
213
|
-
|
|
214
165
|
get minHeight() {
|
|
215
166
|
return this._textarea.style.minHeight;
|
|
216
167
|
}
|
|
217
|
-
|
|
218
168
|
get invalid() {
|
|
219
169
|
return this.props.messages && this.props.messages.findIndex(message => {
|
|
220
170
|
return message.type === 'error';
|
|
221
171
|
}) >= 0;
|
|
222
172
|
}
|
|
223
|
-
|
|
224
173
|
get id() {
|
|
225
174
|
return this.props.id || this._defaultId;
|
|
226
175
|
}
|
|
227
|
-
|
|
228
176
|
get focused() {
|
|
229
177
|
return (0, _isActiveElement.isActiveElement)(this._textarea);
|
|
230
178
|
}
|
|
231
|
-
|
|
232
179
|
get value() {
|
|
233
180
|
return this._textarea.value;
|
|
234
181
|
}
|
|
235
|
-
|
|
236
182
|
render() {
|
|
237
183
|
var _this$props$styles, _this$props$styles2, _this$props$styles3;
|
|
238
|
-
|
|
239
184
|
const _this$props4 = this.props,
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
185
|
+
autoGrow = _this$props4.autoGrow,
|
|
186
|
+
placeholder = _this$props4.placeholder,
|
|
187
|
+
value = _this$props4.value,
|
|
188
|
+
defaultValue = _this$props4.defaultValue,
|
|
189
|
+
disabled = _this$props4.disabled,
|
|
190
|
+
readOnly = _this$props4.readOnly,
|
|
191
|
+
required = _this$props4.required,
|
|
192
|
+
width = _this$props4.width,
|
|
193
|
+
height = _this$props4.height,
|
|
194
|
+
maxHeight = _this$props4.maxHeight,
|
|
195
|
+
textareaRef = _this$props4.textareaRef,
|
|
196
|
+
resize = _this$props4.resize;
|
|
252
197
|
const props = (0, _omitProps.omitProps)(this.props, TextArea.allowedProps);
|
|
253
198
|
const style = {
|
|
254
199
|
width,
|
|
@@ -262,7 +207,6 @@ let TextArea = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
|
|
|
262
207
|
placeholder: placeholder,
|
|
263
208
|
ref: textarea => {
|
|
264
209
|
this._textarea = textarea;
|
|
265
|
-
|
|
266
210
|
if (typeof textareaRef === 'function') {
|
|
267
211
|
textareaRef(textarea);
|
|
268
212
|
}
|
|
@@ -295,7 +239,6 @@ let TextArea = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
|
|
|
295
239
|
"aria-hidden": "true"
|
|
296
240
|
}) : null));
|
|
297
241
|
}
|
|
298
|
-
|
|
299
242
|
}, _class2.displayName = "TextArea", _class2.componentId = 'TextArea', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
|
|
300
243
|
size: 'medium',
|
|
301
244
|
autoGrow: true,
|