-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[TextField] implement suffix/prefix props #19792
Comments
There is a concern to consider with the display when the field is empty and only the label is visible. I might recall a older issue on this very problem. |
I included this already
|
Ok I now remember the underlying issue. I want to abuse the end adornment for a suffix. Changing the alignment would be bad if we have something like a show/hide password toggle. We probably want to implement prefixes/suffixes separately as described in the guidelines: -- https://material.io/components/text-fields/#filled-text-field |
👌 Makes it hard to solve :). |
Maybe we should force the shrink state? |
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). |
Could this be the right place to consider changing the adornment API? Right now you always have to pass the <TextField
startAdornment={<Icon />}
endAdornment="€"
StartAdornmentComponent={SomeOtherAdornmentComponent}
EndAdornmentComponent={SomeOtherAdornmentComponent}
/> This would make the adornment and pre-suffixes simpler to use for almost all use cases. (On that note, it might be interesting to see some custom adornment demos in the docs, without |
<TextField
startAdornment={<Icon />}
endAdornment="€"
StartAdornmentComponent={SomeOtherAdornmentComponent}
EndAdornmentComponent={SomeOtherAdornmentComponent}
/> This is generally an API that I don't find useful. Where would props for
What do you mean by "simpler"? I don't see how -<TextField startAdornment={<SomeOtherAdornmentComponent><Icon /></SomeOtherAdornmentComponent>} />
+<TextField startAdornment={<Icon />} StartAdornmentComponent {SomeOtherAdornmentComponent} /> is simpler. |
It is simpler because StartAdornmentComponent and EndAdornmentComponent would have a defaultvalue of I agree, passing props inside of those components is a bit messy, as you have to either merge // 99% of use-cases
<TextField
startAdornment="€"
/>
// Special use-cases
<TextField
startAdornment="€"
// Optional prop
renderStartAdornment={content => <SomeOtherAdornmentComponent myChildProp={content} type="start" />}
/> 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: // Batteries included!
<TextField
value={amount}
onChange={setAmount}
label="Cost"
startAdornment="€"
/> EDIT: Be more clear about benefits |
I have noticed that the position attribute on the InputAdornment allows one to achieve the stated objective.
They will get the desired output. I have put this in code sand box here |
This can be achieve with som custom styles. Adding a demo to demonstrate how to customize seems to be the best option so far. |
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. |
Current Behavior 😯
Expected Behavior 🤔
Steps to Reproduce 🕹
https://codesandbox.io/s/textfield-endadornment-on-filled-misaligned-rbcyy
Steps:
Context 🔦
Displaying units of the input value for filled inputs
Implementation proposal
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 🌎
The text was updated successfully, but these errors were encountered: