Created
June 20, 2017 19:29
-
-
Save wesdeveloper/927cf48cd5c1027342bb6614f358f2e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import ChipInput from 'material-ui-chip-input' | |
class Chip extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
chips: [], | |
limit: 3 | |
} | |
} | |
handleAddChip (data) { | |
const chips = this.state.chips | |
if(this.state.chips.length <this.state.limit &&data.length < 5){ | |
chips.push(data) | |
console.warn(chips) | |
this.setState({ chips }) | |
} | |
} | |
handleDeleteChip (chip, index) { | |
const chips = this.state.chips | |
chips.splice(index, 1) | |
this.setState({ chips }) | |
} | |
render() { | |
return( | |
<div> | |
<ChipInput | |
value={this.state.chips} | |
onRequestAdd={(chip) => this.handleAddChip(chip)} | |
onRequestDelete={(chip, index) => this.handleDeleteChip(chip, index)} | |
/> | |
</div> | |
) | |
} | |
} | |
export default Chip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment