Skip to content

Commit 010d9cb

Browse files
lcswillemsoliviertassinari
authored andcommitted
[TextareaAutosize] Add rowsMin prop (#18804)
1 parent 5af0078 commit 010d9cb

File tree

7 files changed

+27
-11
lines changed

7 files changed

+27
-11
lines changed

docs/pages/api/input-base.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ It contains a load of style reset and some state logic.
4949
| <span class="prop-name">required</span> | <span class="prop-type">bool</span> | | If `true`, the `input` element will be required. |
5050
| <span class="prop-name">rows</span> | <span class="prop-type">string<br>&#124;&nbsp;number</span> | | Number of rows to display when multiline option is set to true. |
5151
| <span class="prop-name">rowsMax</span> | <span class="prop-type">string<br>&#124;&nbsp;number</span> | | Maximum number of rows to display when multiline option is set to true. |
52+
| <span class="prop-name">rowsMin</span> | <span class="prop-type">string<br>&#124;&nbsp;number</span> | | Minimum number of rows to display when multiline option is set to true. |
5253
| <span class="prop-name">startAdornment</span> | <span class="prop-type">node</span> | | Start `InputAdornment` for this component. |
5354
| <span class="prop-name">type</span> | <span class="prop-type">string</span> | <span class="prop-default">'text'</span> | Type of the `input` element. It should be [a valid HTML5 input type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types). |
5455
| <span class="prop-name">value</span> | <span class="prop-type">any</span> | | The value of the `input` element, required for a controlled component. |

docs/pages/api/textarea-autosize.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
2424

2525
| Name | Type | Default | Description |
2626
|:-----|:-----|:--------|:------------|
27-
| <span class="prop-name">rows</span> | <span class="prop-type">string<br>&#124;&nbsp;number</span> | | Minimum number of rows to display. |
27+
| <span class="prop-name">rows</span> | <span class="prop-type">string<br>&#124;&nbsp;number</span> | | Use `rowsMin` instead. The prop will be removed in v5. |
2828
| <span class="prop-name">rowsMax</span> | <span class="prop-type">string<br>&#124;&nbsp;number</span> | | Maximum number of rows to display. |
29+
| <span class="prop-name">rowsMin</span> | <span class="prop-type">string<br>&#124;&nbsp;number</span> | <span class="prop-default">1</span> | Minimum number of rows to display. |
2930

3031
The `ref` is forwarded to the root element.
3132

docs/src/pages/components/textarea-autosize/MinHeightTextarea.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import React from 'react';
22
import TextareaAutosize from '@material-ui/core/TextareaAutosize';
33

44
export default function MinHeightTextarea() {
5-
return <TextareaAutosize aria-label="minimum height" rows={3} placeholder="Minimum 3 rows" />;
5+
return <TextareaAutosize aria-label="minimum height" rowsMin={3} placeholder="Minimum 3 rows" />;
66
}

docs/src/pages/components/textarea-autosize/MinHeightTextarea.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import React from 'react';
22
import TextareaAutosize from '@material-ui/core/TextareaAutosize';
33

44
export default function MinHeightTextarea() {
5-
return <TextareaAutosize aria-label="minimum height" rows={3} placeholder="Minimum 3 rows" />;
5+
return <TextareaAutosize aria-label="minimum height" rowsMin={3} placeholder="Minimum 3 rows" />;
66
}

packages/material-ui/src/InputBase/InputBase.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ const InputBase = React.forwardRef(function InputBase(props, ref) {
191191
renderSuffix,
192192
rows,
193193
rowsMax,
194+
rowsMin,
194195
startAdornment,
195196
type = 'text',
196197
value: valueProp,
@@ -367,7 +368,7 @@ const InputBase = React.forwardRef(function InputBase(props, ref) {
367368
ref: null,
368369
};
369370
} else if (multiline) {
370-
if (rows && !rowsMax) {
371+
if (rows && !rowsMax && !rowsMin) {
371372
InputComponent = 'textarea';
372373
} else {
373374
inputProps = {
@@ -599,6 +600,10 @@ InputBase.propTypes = {
599600
* Maximum number of rows to display when multiline option is set to true.
600601
*/
601602
rowsMax: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
603+
/**
604+
* Minimum number of rows to display when multiline option is set to true.
605+
*/
606+
rowsMin: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
602607
/**
603608
* Start `InputAdornment` for this component.
604609
*/

packages/material-ui/src/TextareaAutosize/TextareaAutosize.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22

33
export interface TextareaAutosizeProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
44
rowsMax?: string | number;
5+
rowsMin?: string | number;
56
}
67

78
declare const TextareaAutosize: React.ComponentType<

packages/material-ui/src/TextareaAutosize/TextareaAutosize.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ const styles = {
2727
};
2828

2929
const TextareaAutosize = React.forwardRef(function TextareaAutosize(props, ref) {
30-
const { onChange, rows, rowsMax, style, value, ...other } = props;
30+
const { onChange, rows, rowsMax, rowsMin: rowsMinProp = 1, style, value, ...other } = props;
31+
32+
const rowsMin = rows || rowsMinProp;
3133

3234
const { current: isControlled } = React.useRef(value != null);
3335
const inputRef = React.useRef(null);
@@ -60,10 +62,10 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(props, ref)
6062
// The height of the outer content
6163
let outerHeight = innerHeight;
6264

63-
if (rows != null) {
64-
outerHeight = Math.max(Number(rows) * singleRowHeight, outerHeight);
65+
if (rowsMin) {
66+
outerHeight = Math.max(Number(rowsMin) * singleRowHeight, outerHeight);
6567
}
66-
if (rowsMax != null) {
68+
if (rowsMax) {
6769
outerHeight = Math.min(Number(rowsMax) * singleRowHeight, outerHeight);
6870
}
6971
outerHeight = Math.max(outerHeight, singleRowHeight);
@@ -88,7 +90,7 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(props, ref)
8890

8991
return prevState;
9092
});
91-
}, [rows, rowsMax, props.placeholder]);
93+
}, [rowsMax, rowsMin, props.placeholder]);
9294

9395
React.useEffect(() => {
9496
const handleResize = debounce(() => {
@@ -123,7 +125,7 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(props, ref)
123125
onChange={handleChange}
124126
ref={handleRef}
125127
// Apply the rows prop to get a "correct" first SSR paint
126-
rows={rows || 1}
128+
rows={rowsMin}
127129
style={{
128130
height: state.outerHeightStyle,
129131
// Need a large enough different to allow scrolling.
@@ -159,13 +161,19 @@ TextareaAutosize.propTypes = {
159161
*/
160162
placeholder: PropTypes.string,
161163
/**
162-
* Minimum number of rows to display.
164+
* Use `rowsMin` instead. The prop will be removed in v5.
165+
*
166+
* @deprecated
163167
*/
164168
rows: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
165169
/**
166170
* Maximum number of rows to display.
167171
*/
168172
rowsMax: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
173+
/**
174+
* Minimum number of rows to display.
175+
*/
176+
rowsMin: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
169177
/**
170178
* @ignore
171179
*/

0 commit comments

Comments
 (0)