Merge pull request #47 from kadirahq/remove-selected-from-options

Remove setting selected in options
This commit is contained in:
Aruna Herath 2016-09-28 15:49:58 +05:30 committed by GitHub
commit 83527a8e4c
2 changed files with 7 additions and 17 deletions

View File

@ -58,15 +58,11 @@ var SelectType = function (_React$Component) {
(0, _createClass3.default)(SelectType, [{ (0, _createClass3.default)(SelectType, [{
key: '_makeOpt', key: '_makeOpt',
value: function _makeOpt(key, val, selected) { value: function _makeOpt(key, val) {
var opts = { var opts = {
key: key, key: key,
selected: 'selected',
value: key value: key
}; };
if (selected !== key) {
delete opts.selected;
}
return _react2.default.createElement( return _react2.default.createElement(
'option', 'option',
@ -79,16 +75,14 @@ var SelectType = function (_React$Component) {
value: function _options(values) { value: function _options(values) {
var _this2 = this; var _this2 = this;
var selected = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1];
var data = []; var data = [];
if (Array.isArray(values)) { if (Array.isArray(values)) {
data = values.map(function (val) { data = values.map(function (val) {
return _this2._makeOpt(val, val, selected); return _this2._makeOpt(val, val);
}); });
} else { } else {
data = (0, _keys2.default)(values).map(function (key) { data = (0, _keys2.default)(values).map(function (key) {
return _this2._makeOpt(key, values[key], selected); return _this2._makeOpt(key, values[key]);
}); });
} }

View File

@ -15,24 +15,20 @@ const styles = {
}; };
class SelectType extends React.Component { class SelectType extends React.Component {
_makeOpt(key, val, selected) { _makeOpt(key, val) {
const opts = { const opts = {
key, key,
selected: 'selected',
value: key, value: key,
}; };
if (selected !== key) {
delete(opts.selected);
}
return <option {...opts}>{val}</option>; return <option {...opts}>{val}</option>;
} }
_options(values, selected = '') { _options(values) {
let data = []; let data = [];
if (Array.isArray(values)) { if (Array.isArray(values)) {
data = values.map(val => this._makeOpt(val, val, selected)); data = values.map(val => this._makeOpt(val, val));
} else { } else {
data = Object.keys(values).map(key => this._makeOpt(key, values[key], selected)); data = Object.keys(values).map(key => this._makeOpt(key, values[key]));
} }
return data; return data;