erikras / redux-form-material-ui

A set of wrapper components to facilitate using Material UI with Redux Form
http://erikras.github.io/redux-form-material-ui/
MIT License
831 stars 228 forks source link

Checkbox and Radio buttons do not show their label #257

Open aikidoshi opened 6 years ago

aikidoshi commented 6 years ago

I have a redux form working nicely with material-ui using your redux-form-material-ui 5.0 beta 3 and it is fantastic except for the Checkbox and Radio controls.

Using the code off the website (see below) the Checkbox and Radio buttons do not show their label:

                    <Grid item xs={12}>
                        <FormControl component="fieldset" required className={classes.formControl}>
                            <FormLabel component="legend">Gender</FormLabel>
                            <Field name="Gender" component={RadioGroup} className={classes.formControl}>
                                <Radio value="Male" label="Male"/>
                                <Radio value="Female" label="Female"/>
                            </Field>
                        </FormControl>
                    </Grid>
                    <Grid item xs={12}>
                        <FormControl component="fieldset" className={classes.formControl}>
                            <FormLabel component="legend">Flying Solo?</FormLabel>
                            <Field
                                name="Solo"
                                label="Solo Licence"
                                component={Checkbox}
                                className={classes.formControl}
                            />
                        </FormControl>
                    </Grid>

image

pakage.json: "dependencies": { "@material-ui/core": "^1.2.1", "@material-ui/icons": "^1.1.0", "moment": "^2.22.2", "react": "^16.4.1", "react-dom": "^16.4.1", "react-redux": "^5.0.7", "react-router-dom": "^4.2.2", "redux": "^4.0.0", "redux-form": "^7.4.0", "redux-form-material-ui": "^5.0.0-beta.3", "typeface-roboto": "^0.0.54"

kjellski commented 6 years ago

I've got the same problem.

Neo478 commented 6 years ago

Working for me with FormControlLabel:

import FormControlLabel from '@material-ui/core/FormControlLabel';
import {
  Checkbox,
} from 'redux-form-material-ui';

...
// In the render function:
<FormControlLabel
        control={
          <Field
            name="agreeToTerms"
            component={Checkbox}
          />
        }
        label={<span>I accepts the <a>terms and conditions</a></span>}
      />

If you need a custom checkbox, i advise to use an adapter like so:

const CheckboxAdapter = inputProps => (<Checkbox
    {...inputProps}
    value={inputProps.input.value}
    onChange={inputProps.input.onChange}
  />);

and pass it to the 'component' props of 'FormControlLabel'

nubiofreitas commented 5 years ago

I've got the same problem. [2]

lc3t35 commented 5 years ago

I had the same problem (Field from "redux-form/immutable") with

"@material-ui/core": "3.5.1",
"redux-form": "7.4.2",
"redux-form-material-ui": "5.0.0-beta.3",

@Neo478 workaround worked fine

andypaling commented 3 years ago

I have the same problem.