UNPKG

4.36 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright 2017 Palantir Technologies, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.TextArea = void 0;
19var tslib_1 = require("tslib");
20var classnames_1 = tslib_1.__importDefault(require("classnames"));
21var React = tslib_1.__importStar(require("react"));
22var common_1 = require("../../common");
23var props_1 = require("../../common/props");
24// this component is simple enough that tests would be purely tautological.
25/* istanbul ignore next */
26/**
27 * Text area component.
28 *
29 * @see https://blueprintjs.com/docs/#core/components/text-inputs.text-area
30 */
31var TextArea = /** @class */ (function (_super) {
32 tslib_1.__extends(TextArea, _super);
33 function TextArea() {
34 var _this = _super !== null && _super.apply(this, arguments) || this;
35 _this.state = {};
36 // used to measure and set the height of the component on first mount
37 _this.textareaElement = null;
38 _this.handleRef = (0, common_1.refHandler)(_this, "textareaElement", _this.props.inputRef);
39 _this.handleChange = function (e) {
40 if (_this.props.growVertically) {
41 _this.setState({
42 height: e.target.scrollHeight,
43 });
44 }
45 if (_this.props.onChange != null) {
46 _this.props.onChange(e);
47 }
48 };
49 return _this;
50 }
51 TextArea.prototype.componentDidMount = function () {
52 var _a;
53 if (this.props.growVertically && this.textareaElement !== null) {
54 // HACKHACK: this should probably be done in getSnapshotBeforeUpdate
55 /* eslint-disable-next-line react/no-did-mount-set-state */
56 this.setState({
57 height: (_a = this.textareaElement) === null || _a === void 0 ? void 0 : _a.scrollHeight,
58 });
59 }
60 };
61 TextArea.prototype.componentDidUpdate = function (prevProps) {
62 if (prevProps.inputRef !== this.props.inputRef) {
63 (0, common_1.setRef)(prevProps.inputRef, null);
64 this.handleRef = (0, common_1.refHandler)(this, "textareaElement", this.props.inputRef);
65 (0, common_1.setRef)(this.props.inputRef, this.textareaElement);
66 }
67 };
68 TextArea.prototype.render = function () {
69 var _a;
70 var _b = this.props, className = _b.className, fill = _b.fill, inputRef = _b.inputRef, intent = _b.intent, large = _b.large, small = _b.small, growVertically = _b.growVertically, htmlProps = tslib_1.__rest(_b, ["className", "fill", "inputRef", "intent", "large", "small", "growVertically"]);
71 var rootClasses = (0, classnames_1.default)(common_1.Classes.INPUT, common_1.Classes.intentClass(intent), (_a = {},
72 _a[common_1.Classes.FILL] = fill,
73 _a[common_1.Classes.LARGE] = large,
74 _a[common_1.Classes.SMALL] = small,
75 _a), className);
76 // add explicit height style while preserving user-supplied styles if they exist
77 var _c = htmlProps.style, style = _c === void 0 ? {} : _c;
78 if (growVertically && this.state.height != null) {
79 // this style object becomes non-extensible when mounted (at least in the enzyme renderer),
80 // so we make a new one to add a property
81 style = tslib_1.__assign(tslib_1.__assign({}, style), { height: "".concat(this.state.height, "px") });
82 }
83 return (React.createElement("textarea", tslib_1.__assign({}, htmlProps, { className: rootClasses, onChange: this.handleChange, ref: this.handleRef, style: style })));
84 };
85 TextArea.displayName = "".concat(props_1.DISPLAYNAME_PREFIX, ".TextArea");
86 return TextArea;
87}(common_1.AbstractPureComponent2));
88exports.TextArea = TextArea;
89//# sourceMappingURL=textArea.js.map
\No newline at end of file