Skip to content
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

Select: s/allowCreate/canAdd #2

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ var Select = React.createClass({
matchPos: React.PropTypes.string, // (any|start) match the start or entire string when filtering
matchProp: React.PropTypes.string, // (any|label|value) which option property to filter on
inputProps: React.PropTypes.object, // custom attributes for the Input (in the Select-control) e.g: {'data-foo': 'bar'}
allowCreate: React.PropTypes.bool, // whether to allow creation of new entries
onAdd: React.PropTypes.func, // onAdd handler function(newValue, newValues) called when a new value is added before onChange, requires allowCreate = true
canAdd: React.PropTypes.bool, // whether to allow creation of new entries
onAdd: React.PropTypes.func, // onAdd handler function(newValue, newValues) called when a new value is added before onChange, requires canAdd = true
/*
* Allow user to make option label clickable. When this handler is defined we should
* wrap label into <a>label</a> tag.
Expand Down Expand Up @@ -67,7 +67,7 @@ var Select = React.createClass({
matchPos: 'any',
matchProp: 'any',
inputProps: {},
allowCreate: false,
canAdd: false,
onAdd: undefined,

onOptionLabelClick: undefined
Expand Down Expand Up @@ -242,7 +242,7 @@ var Select = React.createClass({
}
var newState = this.getStateFromValue(value);
newState.isOpen = false;
if(this.props.allowCreate) {
if(this.props.canAdd) {
// Find if the value was added
var inputValue = this.state.inputValue;
// Loop through the filtered options
Expand Down Expand Up @@ -307,7 +307,7 @@ var Select = React.createClass({
},

fireAddEvent: function(newState) {
if (newState.value !== this.state.value && this.props.onAdd && this.props.allowCreate) {
if (newState.value !== this.state.value && this.props.onAdd && this.props.canAdd) {
this.props.onAdd(newState.value, newState.values);
}
},
Expand Down Expand Up @@ -406,7 +406,7 @@ var Select = React.createClass({
break;

case 188: // ,
if (this.props.allowCreate) {
if (this.props.canAdd) {
event.preventDefault();
event.stopPropagation();
this.selectFocusedOption();
Expand Down Expand Up @@ -546,7 +546,7 @@ var Select = React.createClass({
},

selectFocusedOption: function() {
if (this.props.allowCreate && !this.state.focusedOption) {
if (this.props.canAdd && !this.state.focusedOption) {
return this.selectValue(this.state.inputValue);
};
return this.selectValue(this.state.focusedOption);
Expand Down Expand Up @@ -626,7 +626,7 @@ var Select = React.createClass({
focusedValue = focusedValue == null ? this.state.filteredOptions[0] : focusedValue;
}
// Add the current value to the filtered options in last resort
if (this.props.allowCreate && !this.state.filteredOptions.length) {
if (this.props.canAdd && !this.state.filteredOptions.length) {
var inputValue = this.state.inputValue;
this.state.filteredOptions.push({
value: inputValue,
Expand Down