[TextField] `InputLabelProps={{ required: true }}` renders incorrectly
See original GitHub issueDuplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
The asterisk used for required TextField
components renders differently if using InputLabelProps={{ required: true }}
to using required
. The former is useful if you want to roll your own validation.
It’s subtle but the spacing to the right of the asterisk is missing on the second TextField
.
So this is OK:
<TextField required />
This has the missing spacing:
<TextField InputLabelProps={{ required: true }} />
Expected behavior 🤔
Using required
or InputLabelProps={{ required: true }}
should render the asterisk consistently.
Steps to reproduce 🕹
https://codesandbox.io/s/clever-frost-fy71ov?file=/src/App.tsx
Context 🔦
No response
Your environment 🌎
`npx @mui/envinfo`
System:
OS: macOS 10.15.7
Binaries:
Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.2/bin/yarn
npm: 8.5.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
Browsers:
Chrome: 99.0.4844.51
Edge: Not Found
Firefox: 96.0.2
Safari: 14.1.2
npmPackages:
@emotion/react: ^11.8.2 => 11.8.2
@emotion/styled: ^11.8.1 => 11.8.1
@mui/base: 5.0.0-alpha.71
@mui/material: ^5.5.0 => 5.5.0
@mui/private-theming: 5.4.4
@mui/styled-engine: 5.4.4
@mui/system: 5.5.0
@mui/types: 7.1.2
@mui/utils: 5.4.4
@types/react: ^17.0.33 => 17.0.40
react: ^17.0.2 => 17.0.2
react-dom: ^17.0.2 => 17.0.2
typescript: ^4.5.4 => 4.6.2
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Material-UI Outlined Input Label Incorrect Alignment
I'm having an issue with TextField labels and placeholder text rendering incorrectly with Material UI. I'm not sure why this is happening as ......
Read more >React Text Field component - Material UI - MUI
The TextField wrapper component is a complete form control including a label, ... Standard form attributes are supported e.g. required , disabled ,...
Read more >Input Components - React-admin - Marmelab
An Input component displays an input, or a dropdown list, a list of radio buttons, etc. ... Input components require a source prop....
Read more >inputlabelprops= shrink true | The AI Search Engine You Control
but the problem is we need to pass it everytime we want to render the autocomplete. ... <TextField label="ML Features" InputLabelProps={{ shrink: true...
Read more >How to conditionally render error and success messages on ...
render () { const { classes } = this.props; console.log(classes); return ( <div> <div id='notification'/> <FormControl fullWidth="true" ...
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
@michaldudak The use case is custom validation. If you pass
required
to aninput
then the built-in browser HTML UI will appear when you try and submit the form - which we do not want. We want to use our own UI for required fields whilst keeping theTextField
asterisk.So we want the label to look exactly the same but without the
required
attribute on the underlyinginput
.HTH.
You can add the asterisk to the label yourself (
<TextField label="Required field *" />
) or override therequired
prop set by the input by setting it toundefined
:<TextField label="Required field" inputProps={{ required: undefined }} />
. Does this solve your problem?