[TextField] implement suffix/prefix props
See original GitHub issueCurrent Behavior 😯
Expected Behavior 🤔
Steps to Reproduce 🕹
<TextField
label="value"
InputProps={{
endAdornment: <InputAdornment position="end">days</InputAdornment>
}}
type="text"
variant="filled"
/>
https://codesandbox.io/s/textfield-endadornment-on-filled-misaligned-rbcyy
Steps:
- Goto https://codesandbox.io/s/textfield-endadornment-on-filled-misaligned-rbcyy
- Observe misalignment
Context 🔦
Displaying units of the input value for filled inputs
Implementation proposal
<TextField
label="value"
InputProps={{
suffix: <InputSuffix>days</InputSuffix>
}}
type="text"
variant="filled"
/>
following https://material.io/components/text-fields/#filled-text-field (see “prefix and suffix text”)
Notes
The alignment uses the baseline of the input without a value (where the label looks like a placeholder). Once we transition to label+value the alignment is off. The Adornment should adjust for this state.
Your Environment 🌎
Tech | Version |
---|---|
Material-UI | v4.9.3 |
React | 16.12 |
Browser | Chrome Version 80.0.3987.116 (Official Build) (64-bit) Ubuntu 18.04 |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:9 (9 by maintainers)
Top Results From Across the Web
[TextField] implement suffix/prefix props · Issue #19792 - GitHub
The alignment uses the baseline of the input without a value (where the label looks like a placeholder). Once we transition to label+value...
Read more >Add suffix follow by user input material ui TextField
1 Answer 1 ; as React ; import NumberFormat ; import TextField ; CustomProps { onChange ; name: string; } const ...
Read more >React Text Field component - Material UI - MUI
The select prop makes the text field use the Select component internally. Select ... This can be used to add a prefix, a...
Read more >Prefix & Suffix Adornments - Kendo UI for Vue Docs & Demos
The Input provides configuration properties for adding items as prefix and suffix adornments. The component can display both built-in and custom adornments.
Read more >Input with prefix and suffix attached - CodePen
URL Extension Required. When linking another Pen as a resource, make sure you use a URL Extension of the type of code you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m favoring separating adornments and affixes. They are already described in guidelines. Forcing the alignment would look weird if your adornment is button-like (see password show/hide toggle).
It is simpler because StartAdornmentComponent and EndAdornmentComponent would have a defaultvalue of
InputAdornment
.I agree, passing props inside of those components is a bit messy, as you have to either merge
children
inside of it, or add another prop to pass props into that component. Or you can turn the prop into a function, and completely invert control, as needed:The point is, for the few times I need to use adornments, I always have to look back at the docs, to find the perfect combination of props, components and content I need to make it look normal. I wish I could simply give material-ui my content, and let it figure out as much as possible which combo of low-level components it should use. You should always be able to customize it, but the TextField component can and should take care of the general use case imho:
EDIT: Be more clear about benefits