From 4861261057fbf0fb473cc9d8207cf4bd7aae293c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrno=20Ader?= Date: Fri, 27 Feb 2015 10:20:03 +0200 Subject: [PATCH] Don't show dropdown if no results by default. Allow to show empty dropdown via zeroDropdown property. Fixed #26 --- dist/multiple.js | 7 ++++++- src/multiple.jsx | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dist/multiple.js b/dist/multiple.js index cde55a5..ec6ec94 100644 --- a/dist/multiple.js +++ b/dist/multiple.js @@ -40,6 +40,7 @@ var MultipleChoice = React.createClass({displayName: 'MultipleChoice', mixins: [SearchMixin], propTypes: { + zeroDropdown: React.PropTypes.bool, // Set to true, to always show dropdown, even if there aren't any options to show name: React.PropTypes.string, // name of input placeholder: React.PropTypes.string, // input placeholder values: React.PropTypes.array, // initial values @@ -145,6 +146,10 @@ var MultipleChoice = React.createClass({displayName: 'MultipleChoice', }, _getAvailableOptions: function(values) { + if (!values) { + values = this.state.values; + } + var options = this.state.initialOptions; var valueField = this.props.valueField; @@ -361,7 +366,7 @@ var MultipleChoice = React.createClass({displayName: 'MultipleChoice', ref: "input"}) ), - this.state.focus ? + this.state.focus && (!this.props.zeroDropdown || options.length > 0) ? React.createElement("div", {className: "react-choice-options", ref: "options"}, React.createElement("ul", {className: "react-choice-options__list"}, options diff --git a/src/multiple.jsx b/src/multiple.jsx index 22bac4b..93f263b 100644 --- a/src/multiple.jsx +++ b/src/multiple.jsx @@ -40,6 +40,7 @@ var MultipleChoice = React.createClass({ mixins: [SearchMixin], propTypes: { + zeroDropdown: React.PropTypes.bool, // Set to true, to always show dropdown, even if there aren't any options to show name: React.PropTypes.string, // name of input placeholder: React.PropTypes.string, // input placeholder values: React.PropTypes.array, // initial values @@ -145,6 +146,10 @@ var MultipleChoice = React.createClass({ }, _getAvailableOptions: function(values) { + if (!values) { + values = this.state.values; + } + var options = this.state.initialOptions; var valueField = this.props.valueField; @@ -361,7 +366,7 @@ var MultipleChoice = React.createClass({ ref="input" /> - {this.state.focus ? + {this.state.focus && (!this.props.zeroDropdown || options.length > 0) ?