Ver Fonte

chore: fix Checkbox,Radio type prop

走鹃 há 3 anos atrás
pai
commit
0eb2a9459f

+ 9 - 2
packages/semi-ui/checkbox/checkboxGroup.tsx

@@ -6,7 +6,7 @@ import { checkboxGroupClasses as css, strings } from '@douyinfe/semi-foundation/
 import CheckboxGroupFoundation, { CheckboxGroupAdapter } from '@douyinfe/semi-foundation/checkbox/checkboxGroupFoundation';
 import BaseComponent from '../_base/baseComponent';
 import { Context } from './context';
-import { isEqual } from 'lodash';
+import { get, isEqual } from 'lodash';
 import Checkbox, { CheckboxEvent } from './checkbox';
 
 export type CheckboxDirection = 'horizontal' | 'vertical';
@@ -161,7 +161,14 @@ class CheckboxGroup extends BaseComponent<CheckboxGroupProps, CheckboxGroupState
                 }
             });
         } else if (children) {
-            inner = (React.Children.toArray(children) as React.ReactElement[]).map((itm, index) => React.cloneElement(itm, { key: index, role: 'listitem' }));
+            inner = (React.Children.toArray(children) as React.ReactElement[]).map((itm, index) => {
+                const props: Record<string, any> = { key: index, role: 'listitem' };
+                const isCheckboxComp = ['Checkbox', 'CheckboxWithGroup'].some(comp => [get(itm, 'type.displayName'), get(itm, 'type.name')].includes(comp));
+                if (isCheckboxComp) {
+                    props.type = type;
+                }
+                return React.cloneElement(itm, props);
+            });
         }
 
         return (

+ 13 - 4
packages/semi-ui/radio/radioGroup.tsx

@@ -1,7 +1,7 @@
 import React from 'react';
 import PropTypes from 'prop-types';
 import classnames from 'classnames';
-import { noop } from 'lodash';
+import { get, noop } from 'lodash';
 
 import { radioGroupClasses as css, strings } from '@douyinfe/semi-foundation/radio/constants';
 import RadioGroupFoundation, { RadioGroupAdapter } from '@douyinfe/semi-foundation/radio/radioGroupFoundation';
@@ -199,9 +199,18 @@ class RadioGroup extends BaseComponent<RadioGroupProps, RadioGroupState> {
                 }
             });
         } else if (children) {
-            inner = React.Children.map(children, (itm, index) => (React.isValidElement(itm) ?
-                React.cloneElement(itm, { key: index }) :
-                null));
+            inner = React.Children.map(children, (itm, index) => {
+                if (React.isValidElement(itm)) {
+                    const props: Record<string, any> = { key: index };
+                    const isRadioComp = ['Radio', 'RadioWithGroup'].some(comp => [get(itm, 'type.displayName'), get(itm, 'type.name')].includes(comp));
+                    if (isRadioComp) {
+                        props.type = type;
+                    }
+                    return React.cloneElement(itm, props);
+                } else {
+                    return null;
+                }
+            });
         }
 
         return (