GithubHelp home page GithubHelp logo

redux-form-material-ui's Introduction


redux-form-material-ui


NPM Version NPM Downloads Build Status codecov.io CDNJS version

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

Latest version is supported by only for material-ui beta.


Live Demo ๐Ÿ‘€

Installation

Using npm:

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

Using yarn:

  $ yarn add redux-form-material-ui@next

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/core/MenuItem'
import Radio from '@material-ui/core/RadioButton'
import {
  Checkbox,
  RadioGroup,
  Select,
  TextField,
  Switch,
  FormControlLabel,
} from 'redux-form-material-ui'

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

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

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

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

        <Field name="bestFramework" component={RadioGroup}>
          <Radio value="react" label="React" />
          <Radio value="angular" label="Angular" />
          <Radio 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>
  )
}

redux-form-material-ui's People

Contributors

erikras avatar mihirsoni avatar gfpacheco avatar jedwards1211 avatar hocdoc avatar sogoiii avatar alphashuro avatar andreapier avatar brian-gaffney avatar bhml avatar chaitanya-bhagavan avatar doaboa avatar hastaragil avatar spart3b avatar extend1994 avatar m14t avatar sigmike avatar undeadlol1 avatar nmaves avatar rehandalal avatar srolija avatar angelinatarapko avatar gitrite avatar pinkstrings avatar nomemoryerror avatar daniel-parreira-prodigy avatar stunaz avatar

Watchers

James Cloos avatar Jason McLaurin avatar  avatar

Forkers

aimin-dev

redux-form-material-ui's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.