Skip to content

Commit

Permalink
Add rowsMin
Browse files Browse the repository at this point in the history
  • Loading branch information
lcswillems authored and oliviertassinari committed Dec 13, 2019
1 parent 3bbc68d commit cbebea6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
14 changes: 13 additions & 1 deletion packages/material-ui/src/InputBase/InputBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const InputBase = React.forwardRef(function InputBase(props, ref) {
renderSuffix,
rows,
rowsMax,
rowsMin,
startAdornment,
type = 'text',
value: valueProp,
Expand Down Expand Up @@ -367,7 +368,7 @@ const InputBase = React.forwardRef(function InputBase(props, ref) {
ref: null,
};
} else if (multiline) {
if (rows && !rowsMax) {
if (rows && !rowsMax && !rowsMin) {
InputComponent = 'textarea';
} else {
inputProps = {
Expand Down Expand Up @@ -600,6 +601,17 @@ InputBase.propTypes = {
*/
rowsMax: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
<<<<<<< HEAD
=======
* Minimum number of rows to display when multiline option is set to true.
*/
rowsMin: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Should be `true` when the component hosts a select.
*/
select: PropTypes.bool,
/**
>>>>>>> Add rowsMin
* Start `InputAdornment` for this component.
*/
startAdornment: PropTypes.node,
Expand Down
20 changes: 14 additions & 6 deletions packages/material-ui/src/TextareaAutosize/TextareaAutosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const styles = {
};

const TextareaAutosize = React.forwardRef(function TextareaAutosize(props, ref) {
const { onChange, rows, rowsMax, style, value, ...other } = props;
const { onChange, rows, rowsMax, rowsMin: rowsMinProp = 1, style, value, ...other } = props;

const rowsMin = rowsMinProp || rows;

const { current: isControlled } = React.useRef(value != null);
const inputRef = React.useRef(null);
Expand Down Expand Up @@ -60,8 +62,8 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(props, ref)
// The height of the outer content
let outerHeight = innerHeight;

if (rows != null) {
outerHeight = Math.max(Number(rows) * singleRowHeight, outerHeight);
if (rowsMin != null) {
outerHeight = Math.max(Number(rowsMin) * singleRowHeight, outerHeight);
}
if (rowsMax != null) {
outerHeight = Math.min(Number(rowsMax) * singleRowHeight, outerHeight);
Expand All @@ -88,7 +90,7 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(props, ref)

return prevState;
});
}, [rows, rowsMax, props.placeholder]);
}, [rowsMax, rowsMin, props.placeholder]);

React.useEffect(() => {
const handleResize = debounce(() => {
Expand Down Expand Up @@ -123,7 +125,7 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(props, ref)
onChange={handleChange}
ref={handleRef}
// Apply the rows prop to get a "correct" first SSR paint
rows={rows || 1}
rows={rowsMin}
style={{
height: state.outerHeightStyle,
// Need a large enough different to allow scrolling.
Expand Down Expand Up @@ -159,13 +161,19 @@ TextareaAutosize.propTypes = {
*/
placeholder: PropTypes.string,
/**
* Minimum number of rows to display.
* Use `rowsMin` instead
*
* @deprecated
*/
rows: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Maximum number of rows to display.
*/
rowsMax: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Minimum number of rows to display.
*/
rowsMin: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* @ignore
*/
Expand Down

0 comments on commit cbebea6

Please sign in to comment.