Comments (3)
Hi, I was just checking the repo for examples on the Select component because I'm lazy; and stumbled upon this.
There's a really easy fix to this 'problem' actually. It's a MUI feature where you can set the select component to display fields with empty values or keep the content even if there's no value.
All we need to do in order to display items with no values is set the boolean displayEmpty
to true. With formik, you do it on the Field
component, as it passes those specific props on. Here's the edited Field
component
You can read more about the props specific to Select here: https://material-ui.com/api/select/#props
The MUI components can be quite tricky sometimes, so be sure read their docs when using their components. The docs are really great (especially the examples) and something I have to reference often even though I've used MUI a bunch.
from formik-mui.
@MathiasKandelborg That's for the tip and that works. This was working properly a while ago but we have switched from redux-form to Formik (and of course Formik MUI) and updated MUI itself several times since then. I don't know if MUI added this during that time or something with redux-form was making it work, or ??? Anyway it's working again so I'm good!
from formik-mui.
One other thing I just discovered in case anyone else comes to this issue. If you're using an <InputLabel>
you need to add shrink prop to keep it form putting the label over None in the select.
<FormControl className={classes.formControl}>
<InputLabel shrink htmlFor="age-label-placeholder">
Age
</InputLabel>
<Select
value={state.age}
onChange={handleChange}
input={<Input name="age" id="age-label-placeholder" />}
displayEmpty
name="age"
className={classes.selectEmpty}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>Label + placeholder</FormHelperText>
</FormControl>
from formik-mui.
Related Issues (20)
- The `Select` component doesn't adapt the label to the used variant HOT 2
- Add the npm installation script for documentation section
- TextField does not accept numeric value when using react-number-format
- Select contain box overlaps label HOT 2
- Ability to disable default blur handler HOT 6
- Reflect MUI changes regarding Date and Time pickers moved to MUI X from lab HOT 3
- Missing support for freesolo with Autocomplete HOT 1
- GH Pages Deploy Broken
- [DOCS] Reflect MUI changes regarding Date and Time pickers moved to MUI X from lab HOT 2
- when select size
- [BUG Select] Use HTMLElement.dataset to get option values in Select doesn't work HOT 4
- What is the `sxFormControl` in select `formControl` prop HOT 1
- numeric Select values are converted to a string
- Multiline TextField fullWidth is not working HOT 1
- ToggleButtonGroup should disable while submitting
- TextField label gets in the way with initial Chrome autofill value
- Support for Mui X v6 HOT 7
- Usage of `formError` in `fieldToSelect`?
- Date Field
- Following syntax for Autocomplete in docs yields onBlur error, while using the <MuiTextField /> instead "works" HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from formik-mui.