Skip to content

Commit a146070

Browse files
sam019e1emeb0t
authored andcommitted
Fix Checkbox
1 parent 669e9af commit a146070

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/checkbox/CheckBox.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ type State = {
1010
}
1111

1212
export default class Checkbox extends Component {
13+
static elementType = 'Checkbox';
14+
1315
state: State;
1416

1517
constructor(props: Object) {

src/checkbox/CheckBoxButton.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import React from 'react';
44
import CheckBox from './CheckBox';
55

66
export default class CheckboxButton extends CheckBox {
7+
static elementType = 'CheckboxButton';
8+
79
render(): React.Element<any> {
810
const group = this.context.ElCheckboxGroup;
911

src/checkbox/CheckBoxGroup.jsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
import React, { Children } from 'react';
44
import { Component, PropTypes } from '../../libs'
55

6-
import Checkbox from './CheckBox';
7-
import CheckboxButton from './CheckBoxButton';
8-
96
type State = {
107
options: Array<string>,
118
}
@@ -60,9 +57,13 @@ export default class CheckboxGroup extends Component {
6057
if (!child) {
6158
return null;
6259
}
63-
if (child.type !== Checkbox || child.type !== CheckboxButton) {
64-
throw new Error(`"CheckboxGroup's children must be Checkbox or CheckboxButton, but received '${child.type}'"`)
60+
61+
const { elementType } = child.type;
62+
// 过滤非Checkbox和CheckboxButton的子组件
63+
if (elementType !== 'Checkbox' && elementType !== 'CheckboxButton') {
64+
return null;
6565
}
66+
6667
return React.cloneElement(
6768
child,
6869
Object.assign({}, child.props, {
@@ -93,4 +94,4 @@ CheckboxGroup.propTypes = {
9394
textColor: PropTypes.string,
9495
value: PropTypes.any,
9596
onChange: PropTypes.func,
96-
}
97+
};

0 commit comments

Comments
 (0)