Skip to content
Open
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
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import Styles from './styles'
const propTypes = {
options: React.PropTypes.array.isRequired,
selectedOptions: React.PropTypes.array,
updateSelectedOptions: PropTypes.bool,
optionIndex: PropTypes.func,
isSelected: PropTypes.func,
maxSelectedOptions: React.PropTypes.number,
onSelection: React.PropTypes.func,
renderIndicator: React.PropTypes.func,
Expand All @@ -28,6 +31,7 @@ const propTypes = {
const defaultProps = {
options: [],
selectedOptions: [],
updateSelectedOptions: true,
onSelection(option){},
style:{},
optionStyle:{},
Expand Down Expand Up @@ -57,7 +61,9 @@ class MultipleChoice extends BaseComponent {
}

componentWillReceiveProps(nextProps) {
this._updateSelectedOptions(nextProps.selectedOptions);
if (this.props.updateSelectedOptions) {
this._updateSelectedOptions(nextProps.selectedOptions);
}
this.setState({
disabled: nextProps.disabled
});
Expand All @@ -83,7 +89,9 @@ class MultipleChoice extends BaseComponent {
_selectOption(selectedOption) {

let selectedOptions = this.state.selectedOptions;
const index = selectedOptions.indexOf(selectedOption);
const index = typeof this.props.optionIndex === 'function' ?
this.props.optionIndex(selectedOptions, selectedOption) :
selectedOptions.indexOf(selectedOption);

if (index === -1) {
this._validateMaxSelectedOptions();
Expand All @@ -103,7 +111,7 @@ class MultipleChoice extends BaseComponent {
}

_renderIndicator(option) {
if (this._isSelected(option)) {
if ((typeof this.props.isSelected === 'function' && this.props.isSelected(this.state.selectedOptions, option)) || this._isSelected(option)) {
if(typeof this.props.renderIndicator === 'function') {
return this.props.renderIndicator(option);
}
Expand Down