1.3.0 • Published 8 years ago

react-material-select v1.3.0

Weekly downloads
42
License
MIT
Repository
github
Last release
8 years ago

React Material Select

I just wanted to have React select element in the Material Design. So I did it.


Installation

$ npm i react-material-select --save


Examples

http://react-material-select.netlify.com/


Documentation

All parameters:

<ReactMaterialSelect ...>
parameterdescriptionis required
onChangecallback function (function)no
defaultValuestart value. One of dataValue keys. Default: null (string)no
labellabel for select. Default: null (string)no
resetLabellabel for reset select value. Default: 'No value' (string) it also can be boolean value "false"no
<option ...>
parameterdescriptionis required
dataValueselected value (string)yes

All methods

methoddescription
this.getValue()get selected value
this.getLabel()get selected label
this.handleToggleSelect()open / close selector
this.handleResetSelect()reset selector value and label
this.handleSetSelect(label, value)set specified value and label to selector
this.getOptions()get all available options as an array of objects

Basic Usage:

It should looks like below:

import React, {Component} from 'react'
import ReactMaterialSelect from 'react-material-select'
import 'react-material-select/lib/css/reactMaterialSelect.css'

class Example extends Component {
    render() {
        return (
            <ReactMaterialSelect>
                <option dataValue="Star Wars">Darth Vader</option>
                ...
            </ReactMaterialSelect>
        )
    }
}

Get value and label from refs

import React, {Component} from 'react'
import ReactMaterialSelect from 'react-material-select'
import 'react-material-select/lib/css/reactMaterialSelect.css'

getValue() {
    this.setState({
        selected1: {
            value: this.refs.firstselect.getValue(),
            label: this.refs.firstselect.getLabel(),
        },
    })
}

class Example extends Component {
    render() {
        return (
            <ReactMaterialSelect ref="firstselect">
                <option dataValue="Star Wars">Darth Vader</option>
                ...
            </ReactMaterialSelect>
            <button onClick={this.getValue.bind(this)}>Get value and label from select</button>
        )
    }
}

Get value from callback function (with all props)

import React, {Component} from 'react'
import ReactMaterialSelect from 'react-material-select'
import 'react-material-select/lib/css/reactMaterialSelect.css'

constructor() {
    super()

    this.state = {
        object: {},
    }

    this.callbackFunction = this.callbackFunction.bind(this)
}

callbackFunction(selected) {
    this.setState({object: selected})
}

class Example extends Component {
    render() {
        return (
            <ReactMaterialSelect label="Choose favourite film character" defaultValue="The Godfather" resetLabel="None of them" onChange={this.callbackFunction}>
                <option dataValue="The Godfather">Vito Corleone</option>
                ...
            </ReactMaterialSelect>
        )
    }
}

Contributing

To remember how to do it ;)

  1. change version of the package
  2. npm run compile
  3. npm run build
  4. git commit
  5. npm publish
1.3.0

8 years ago

1.2.1

8 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.14

9 years ago

1.0.13

9 years ago

1.0.12

9 years ago

1.0.11

9 years ago

1.0.10

9 years ago

1.0.9

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago