Use a special static property for type detecting

close #5359
This commit is contained in:
Wei Zhu 2017-03-17 17:54:02 +08:00
parent 8f81594f91
commit 54b49afd32
3 changed files with 5 additions and 3 deletions

View File

@ -1,7 +1,5 @@
import React from 'react';
import classNames from 'classnames';
import Radio from './radio';
import RadioButton from './radioButton';
import PureRenderMixin from 'rc-util/lib/PureRenderMixin';
import assign from 'object-assign';
@ -87,7 +85,7 @@ export default class RadioGroup extends React.Component<RadioGroupProps, any> {
render() {
const props = this.props;
const children = !props.children ? [] : React.Children.map(props.children, (radio: any) => {
if (radio && (radio.type === Radio || radio.type === RadioButton) && radio.props) {
if (radio && radio.type && (radio.type.__ANT_RADIO || radio.type.__ANT_RADIO_BUTTON) && radio.props) {
return React.cloneElement(radio, assign({}, radio.props, {
onChange: this.onRadioChange,
checked: this.state.value === radio.props.value,

View File

@ -20,6 +20,8 @@ export interface RadioProps {
}
export default class Radio extends React.Component<RadioProps, any> {
static __ANT_RADIO = true;
static Group: any;
static Button: any;

View File

@ -7,6 +7,8 @@ export interface RadioButtonProps {
}
export default class RadioButton extends React.Component<RadioButtonProps, any> {
static __ANT_RADIO_BUTTON = true;
static defaultProps = {
prefixCls: 'ant-radio-button',
};