Skip to content

Commit 3d21902

Browse files
committed
Sync with Kendo UI Professional
1 parent 49917d9 commit 3d21902

File tree

3 files changed

+67
-18
lines changed

3 files changed

+67
-18
lines changed

docs/api/javascript/ui/textarea.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,14 @@ If set to `true`, the widget will be readonly and will not allow user input. The
264264

265265
### resize `String`*(default: "none")*
266266

267+
The `auto` option can be used only with the `maxRows` configuration.
268+
267269
Sets a value controlling how the resize is applied. Can also be set to the following string values:
268270

269271
- "both"
270272
- "horizontal"
271273
- "vertical"
274+
- "auto"
272275
- "none"
273276

274277
#### Example
@@ -406,6 +409,20 @@ Sets a value controlling size of the component. Can also be set to the following
406409
});
407410
</script>
408411

412+
### maxRows `Number` *(default: null)*
413+
414+
The maximum number of visible rows to which the textarea can auto-resize. Used in combination with `resize: "auto"`.
415+
416+
#### Example - specify maxRows
417+
418+
<textarea id="description"></textarea>
419+
<script>
420+
$("#description").kendoTextArea({
421+
autoResize: true,
422+
maxRows: 5
423+
})
424+
</script>
425+
409426
## Methods
410427

411428
### destroy

src/kendo.textarea.js

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export const __meta__ = {
8686
label: null,
8787
resizable: "none",
8888
maxLength: null,
89+
maxRows: null,
8990
cols: 20,
9091
rows: 1,
9192
rounded: "medium",
@@ -103,27 +104,29 @@ export const __meta__ = {
103104
},
104105

105106
_applyCssClasses: function(action) {
106-
var that = this,
107-
options = that.options,
108-
resize = kendo.cssProperties.getValidClass({
109-
widget: options.name,
110-
propName: "resize",
111-
value: options.resize
112-
}),
113-
overflow = kendo.cssProperties.getValidClass({
114-
widget: options.name,
115-
propName: "overflow",
116-
value: options.overflow
117-
}),
118-
layoutFlow = kendo.cssProperties.getValidClass({
119-
widget: options.name,
120-
propName: "layoutFlow",
121-
value: options.layoutFlow
122-
});
107+
let that = this;
108+
let options = that.options;
109+
let resize = kendo.cssProperties.getValidClass({
110+
widget: options.name,
111+
propName: "resize",
112+
value: options.resize
113+
});
114+
115+
let overflow = kendo.cssProperties.getValidClass({
116+
widget: options.name,
117+
propName: "overflow",
118+
value: options.overflow
119+
});
120+
121+
let layoutFlow = kendo.cssProperties.getValidClass({
122+
widget: options.name,
123+
propName: "layoutFlow",
124+
value: options.layoutFlow
125+
});
123126

124127
Widget.fn._applyCssClasses.call(that);
125128

126-
if (!resize && options.resize === "none") {
129+
if (!resize && (options.resize === "none" || options.resize === "auto")) {
127130
resize = "k-resize-none";
128131
}
129132

@@ -245,6 +248,7 @@ export const __meta__ = {
245248

246249
element.on("focusin" + NS, that._focusin.bind(that));
247250
element.on("focusout" + NS, that._focusout.bind(that));
251+
element.on("input" + NS, that._input.bind(that));
248252
} else {
249253
element.attr(DISABLED, disable)
250254
.attr(READONLY, readonly)
@@ -314,6 +318,33 @@ export const __meta__ = {
314318
}
315319
},
316320

321+
_input: function() {
322+
const that = this;
323+
const element = that.element;
324+
const options = that.options;
325+
326+
if (options.resize === "auto" && options.maxRows) {
327+
const computedStyle = getComputedStyle(element[0]);
328+
const lineHeight = parseInt(computedStyle.lineHeight, 10) || 16;
329+
const paddingTop = parseInt(computedStyle.paddingTop, 10) || 0;
330+
const paddingBottom = parseInt(computedStyle.paddingBottom, 10) || 0;
331+
const totalPadding = paddingTop + paddingBottom;
332+
const minHeight = (options.rows * lineHeight) + totalPadding;
333+
const maxHeight = (options.maxRows * lineHeight) + totalPadding;
334+
335+
element.css({
336+
height: minHeight + "px"
337+
});
338+
339+
const scrollHeight = element[0].scrollHeight;
340+
341+
element.css({
342+
maxHeight: maxHeight + "px",
343+
height: scrollHeight + "px"
344+
});
345+
}
346+
},
347+
317348
_wrapper: function() {
318349
var that = this;
319350
var element = that.element;

typescript/kendo.all.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12894,6 +12894,7 @@ declare namespace kendo.ui {
1289412894
inputMode?: string | undefined;
1289512895
label?: string | Function | TextAreaLabel | undefined;
1289612896
maxLength?: number | undefined;
12897+
maxRows?: number | undefined;
1289712898
placeholder?: string | undefined;
1289812899
readonly?: boolean | undefined;
1289912900
rows?: number | undefined;

0 commit comments

Comments
 (0)