question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TextField] implement suffix/prefix props

See original GitHub issue

Current Behavior 😯

Screenshot from 2020-02-21 09-59-58

Expected Behavior 🤔

filled-end-alignment

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:

  1. Goto https://codesandbox.io/s/textfield-endadornment-on-filled-misaligned-rbcyy
  2. 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:open
  • Created 4 years ago
  • Reactions:4
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
eps1loncommented, Feb 21, 2020

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).

0reactions
Floriferouscommented, Apr 14, 2020

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:

// 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found