Fix #630
parent
cd72ffb440
commit
ccc1699cc4
|
@ -2,6 +2,7 @@ import React, { Component, PropTypes } from 'react';
|
|||
import { themr } from 'react-css-themr';
|
||||
import { RADIO } from '../identifiers.js';
|
||||
import InjectRadioButton from './RadioButton.js';
|
||||
import { isComponentOfType } from '../utils/react.js';
|
||||
|
||||
const factory = (RadioButton) => {
|
||||
class RadioGroup extends Component {
|
||||
|
@ -24,12 +25,14 @@ const factory = (RadioButton) => {
|
|||
};
|
||||
|
||||
renderRadioButtons () {
|
||||
return React.Children.map(this.props.children, radio => (
|
||||
React.cloneElement(radio, {
|
||||
checked: radio.props.value === this.props.value,
|
||||
disabled: this.props.disabled || radio.props.disabled,
|
||||
onChange: this.handleChange.bind(this, radio.props.value)
|
||||
})
|
||||
return React.Children.map(this.props.children, child => (
|
||||
!isComponentOfType(RadioButton, child)
|
||||
? child
|
||||
: React.cloneElement(child, {
|
||||
checked: child.props.value === this.props.value,
|
||||
disabled: this.props.disabled || child.props.disabled,
|
||||
onChange: this.handleChange.bind(this, child.props.value)
|
||||
})
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
export function isComponentOfType (classType, reactElement) {
|
||||
return reactElement && reactElement.type === classType;
|
||||
}
|
|
@ -19,6 +19,8 @@ var _RadioButton = require('./RadioButton.js');
|
|||
|
||||
var _RadioButton2 = _interopRequireDefault(_RadioButton);
|
||||
|
||||
var _react3 = require('../utils/react.js');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
@ -52,11 +54,11 @@ var factory = function factory(RadioButton) {
|
|||
value: function renderRadioButtons() {
|
||||
var _this2 = this;
|
||||
|
||||
return _react2.default.Children.map(this.props.children, function (radio) {
|
||||
return _react2.default.cloneElement(radio, {
|
||||
checked: radio.props.value === _this2.props.value,
|
||||
disabled: _this2.props.disabled || radio.props.disabled,
|
||||
onChange: _this2.handleChange.bind(_this2, radio.props.value)
|
||||
return _react2.default.Children.map(this.props.children, function (child) {
|
||||
return !(0, _react3.isComponentOfType)(RadioButton, child) ? child : _react2.default.cloneElement(child, {
|
||||
checked: child.props.value === _this2.props.value,
|
||||
disabled: _this2.props.disabled || child.props.disabled,
|
||||
onChange: _this2.handleChange.bind(_this2, child.props.value)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isComponentOfType = isComponentOfType;
|
||||
function isComponentOfType(classType, reactElement) {
|
||||
return reactElement && reactElement.type === classType;
|
||||
}
|
Loading…
Reference in New Issue