File tree Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ type State = {
10
10
}
11
11
12
12
export default class Checkbox extends Component {
13
+ static elementType = 'Checkbox' ;
14
+
13
15
state : State ;
14
16
15
17
constructor ( props : Object ) {
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import React from 'react';
4
4
import CheckBox from './CheckBox' ;
5
5
6
6
export default class CheckboxButton extends CheckBox {
7
+ static elementType = 'CheckboxButton' ;
8
+
7
9
render ( ) : React . Element < any > {
8
10
const group = this . context . ElCheckboxGroup ;
9
11
Original file line number Diff line number Diff line change 3
3
import React , { Children } from 'react' ;
4
4
import { Component , PropTypes } from '../../libs'
5
5
6
- import Checkbox from './CheckBox' ;
7
- import CheckboxButton from './CheckBoxButton' ;
8
-
9
6
type State = {
10
7
options : Array < string > ,
11
8
}
@@ -60,9 +57,13 @@ export default class CheckboxGroup extends Component {
60
57
if ( ! child ) {
61
58
return null ;
62
59
}
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 ;
65
65
}
66
+
66
67
return React . cloneElement (
67
68
child ,
68
69
Object . assign ( { } , child . props , {
@@ -93,4 +94,4 @@ CheckboxGroup.propTypes = {
93
94
textColor : PropTypes . string ,
94
95
value : PropTypes . any ,
95
96
onChange : PropTypes . func ,
96
- }
97
+ } ;
You can’t perform that action at this time.
0 commit comments