Skip to content
A set of wrapper components to facilitate using Material UI with Redux Form
JavaScript HTML
Branch: master
Clone or download
Latest commit 5d4c156 Apr 7, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example Release 4.3.2 Jan 7, 2018
src AutoComplete: Also pass index Feb 1, 2018
.babelrc Dependency Update and Example Repair (#71) Dec 1, 2016
.eslintignore first commit May 23, 2016
.eslintrc Updated deps Sep 1, 2017
.gitignore Dependency Update and Example Repair (#71) Dec 1, 2016
.npmignore first commit May 23, 2016
.travis.yml Moved Material-UI to a peer dependency (#174) Sep 1, 2017
LICENSE first commit May 23, 2016
README.md Updated Readme for use of V1 beta Oct 14, 2017
index.d.ts fix AutoComplete component declare in index.d.ts file Nov 23, 2017
package-lock.json
package.json Release 4.3.4 Apr 7, 2018
webpack.config.js Updated deps (#129) Apr 14, 2017

README.md


redux-form-material-ui


NPM Version NPM Downloads Build Status codecov.io CDNJS version

For material-ui v1-beta support see 5.0 Documentation.

redux-form-material-ui is a set of wrappers to facilitate the use of material-ui components with redux-form.


Live Demo 👀

Installation

Using npm:

  $ npm install --save redux-form-material-ui

Available Components

Usage

Rather than import your component class from material-ui, import it from redux-form-material-ui and then pass the component class directly to the component prop of Field.

import { reduxForm, Field } from 'redux-form'
import MenuItem from 'material-ui/MenuItem'
import { RadioButton } from 'material-ui/RadioButton'
import {
  Checkbox,
  RadioButtonGroup,
  SelectField,
  TextField,
  Toggle,
  DatePicker
} from 'redux-form-material-ui'

class MyForm extends Component {
  render() {
    return (
      <form>
        <Field name="username" component={TextField} hintText="Street"/>

        <Field name="plan" component={SelectField} hintText="Select a plan">
          <MenuItem value="monthly" primaryText="Monthly"/>
          <MenuItem value="yearly" primaryText="Yearly"/>
          <MenuItem value="lifetime" primaryText="Lifetime"/>
        </Field>

        <Field name="agreeToTerms" component={Checkbox} label="Agree to terms?"/>

        <Field name="eventDate" component={DatePicker} format={null} hintText="What day is the event?"/>

        <Field name="receiveEmails" component={Toggle} label="Please spam me!"/>

        <Field name="bestFramework" component={RadioButtonGroup}>
          <RadioButton value="react" label="React"/>
          <RadioButton value="angular" label="Angular"/>
          <RadioButton value="ember" label="Ember"/>
        </Field>
      </form>
    )
  }
}

// Decorate with redux-form
MyForm = reduxForm({
  form: 'myForm'
})(MyForm)

export default MyForm

No Default Values

Because of the strict "controlled component" nature of redux-form, some of the Material UI functionality related to defaulting of values has been disabled e.g. defaultValue, defaultDate, defaultTime, defaultToggled, defaultChecked, etc. If you need a field to be initialized to a certain state, you should use the initialValues API of redux-form.

Instance API

getRenderedComponent()

Returns a reference to the Material UI component that has been rendered. This is useful for calling instance methods on the Material UI components. For example, if you wanted to focus on the username element when your form mounts, you could do:

componentWillMount() {
  this.refs.firstField      // the Field
    .getRenderedComponent() // on Field, returns ReduxFormMaterialUITextField
    .getRenderedComponent() // on ReduxFormMaterialUITextField, returns TextField
    .focus()                // on TextField
}

as long as you specified a ref and withRef on your Field component.

render() {
  return (
    <form>
      ...
      <Field name="username" component={TextField} withRef ref="firstField"/>
      ...
    </form>
  )
}
You can’t perform that action at this time.