-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TextareaAutosize] Add a rowsMin
prop
#18314
Comments
This comment has been minimized.
This comment has been minimized.
Okay, I see. It already uses it under the hood. So, the only part relevant of my message is:
Or maybe only a |
@lcswillems Thanks for the report. Something is not right. This logic breaks the consistency between the TextareaAutosize component and the InputBase: For consistency, if we add a new prop, it should be named Here are two different alternatives API:
I assume that in most cases, people will need to set a maximum number of rows (do you confirm?) However, we should aim for an intuitive API. Ok, I think that I would support this change, I suspect it would be more intuitive to the many:
Would you confirm? |
I don't know if what people uses most. Personally, I only needed Yes, I confirm both points. |
autosize
property to TextFieldrowsMin
prop
I think that the diff would look something like this: diff --git a/packages/material-ui/src/InputBase/InputBase.js b/packages/material-ui/src/InputBase/InputBase.js
index e425bd307..27446a3a9 100644
--- a/packages/material-ui/src/InputBase/InputBase.js
+++ b/packages/material-ui/src/InputBase/InputBase.js
@@ -191,6 +191,7 @@ const InputBase = React.forwardRef(function InputBase(props, ref) {
renderSuffix,
rows,
rowsMax,
+ rowsMin,
startAdornment,
type = 'text',
value: valueProp,
@@ -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 = {
@@ -599,6 +600,10 @@ InputBase.propTypes = {
* Maximum number of rows to display when multiline option is set to true.
*/
rowsMax: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
+ /**
+ * Minimum number of rows to display when multiline option is set to true.
+ */
+ rowsMin: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Start `InputAdornment` for this component.
*/
diff --git a/packages/material-ui/src/TextareaAutosize/TextareaAutosize.js b/packages/material-ui/src/TextareaAutosize/TextareaAutosize.js
index d7040ddc1..65dd103b3 100644
--- a/packages/material-ui/src/TextareaAutosize/TextareaAutosize.js
+++ b/packages/material-ui/src/TextareaAutosize/TextareaAutosize.js
@@ -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);
@@ -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);
@@ -88,7 +90,7 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(props, ref)
return prevState;
});
- }, [rows, rowsMax, props.placeholder]);
+ }, [rowsMin, rowsMax, props.placeholder]);
React.useEffect(() => {
const handleResize = debounce(() => {
@@ -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.
@@ -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
*/ |
rowsMin
proprowsMin
prop
Yes, that looks good for me. I can do a PR for it if needed! |
@lcswillems This would be awesome :) |
Summary 💡
Add a
autosize
property to TextField to be used with themultiline
prop.With
autosize
, I would expectrows
define the minimum number of rows.Motivation 🔦
The TextareaAutosize had been released recently but the UI is ugly. It would be nice if it could be used with the TextField component. If it is already possible, I couldn't find any documentation about it.
The text was updated successfully, but these errors were encountered: