Reputation: 117
Currently I am developing mobile enterprise web with ReactJs/Material UI and I have question How to show the user a character longer than the limited width TextField
.
Of course, users can see all the characters by touching the text field and moving the cursor, but I need a more effective method.
Below are the ideas I have come up with.
TextField
is not touched, The effect of moving back and forth to make the entire text visible)multiline
text field when the user touches the text field. (dynamic multiline
by whole length of text)Any idea?
Upvotes: 4
Views: 10126
Reputation: 81270
I'd keep it simple:
For long text (content, description...): I'll just set it to multiline
For short text (email, password...) I'll set fullWidth
on mobile.
There is no need to be overthinking. Look at the forms from the most popular websites you know, do you see anything other than fullWidth
or multiline
?
But if you set the TextField
to multiline
you can make it auto resize when there is not enough space to display the long text by setting resize: both
in css. The default is none
(disabled).
const useStyles = makeStyles({
textarea: {
resize: "both"
}
});
<TextField
label="MUI Text Area"
multiline
inputProps={{ className: classes.textarea }}
/>
Or simply:
<TextField
label="MUI Text Area"
multiline
inputProps={{ style: { resize: "both" } }}
/>
You can also use TextareaAutosize
but it sucks and looks nothing like a MUI component out-of-the-box, so don't use it.
Upvotes: 7