-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented allowCreate and more flexible add item on comma functionality #999
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
06f429c
adding back in the allowCreate functionality
a070466
added support for custom add item key code
77fbe10
fixed issues when using allowCreate and simpleValue together
2fee64c
fixed code based on failing test
8f52d46
refactored createNewOption to always add create: true property
aa7f000
Fix filter for numerical options
nadavspi fad706d
Merge pull request #1 from nadavspi/allow_create
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react'; | ||
import Select from 'react-select'; | ||
|
||
const FLAVOURS = [ | ||
{ label: 'Chocolate', value: 42 }, | ||
{ label: 'Vanilla', value: 'vanilla' }, | ||
{ label: 'Strawberry', value: 'strawberry' }, | ||
{ label: 'Caramel', value: 'caramel' }, | ||
{ label: 'Cookies and Cream', value: 'cookiescream' }, | ||
{ label: 'Peppermint', value: 'peppermint' }, | ||
]; | ||
|
||
var AllowCreate = React.createClass({ | ||
displayName: 'AllowCreate', | ||
|
||
propTypes: { | ||
allowCreate: React.PropTypes.bool, | ||
label: React.PropTypes.string, | ||
}, | ||
|
||
getInitialState () { | ||
return { | ||
disabled: false, | ||
crazy: false, | ||
options: FLAVOURS, | ||
value: [], | ||
}; | ||
}, | ||
|
||
onLabelClick (data, event) { | ||
console.log(data, event); | ||
}, | ||
|
||
handleSelectChange (value){ | ||
this.setState({ value }); | ||
}, | ||
|
||
renderHint () { | ||
return ( | ||
<div className="hint">Create options in tag mode</div> | ||
); | ||
}, | ||
|
||
render () { | ||
return ( | ||
<div className="section"> | ||
<h3 className="section-heading">{this.props.label}</h3> | ||
<Select | ||
allowCreate={this.props.allowCreate} | ||
value={this.state.value} | ||
multi | ||
placeholder="Select your favourite(s)" | ||
options={this.state.options} | ||
onChange={this.handleSelectChange} | ||
addItemOnKeyCode={188} | ||
/> | ||
|
||
{this.renderHint()} | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
module.exports = AllowCreate; |
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using custom keys (
valueKey
,labelKey
) this causes:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it needs to be changed to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nadavspi cool ! note that you inadvertently forgot a
]
👼