Browse Source

fix: Radio.Group options: Element type is invalid (#24666)

pull/24685/head
Tom Xu 5 years ago
committed by GitHub
parent
commit
edf7805922
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      components/radio/index.tsx
  2. 13
      components/radio/radio.tsx

9
components/radio/index.tsx

@ -1,9 +1,16 @@
import Radio from './radio'; import InternalRadio from './radio';
import Group from './group'; import Group from './group';
import Button from './radioButton'; import Button from './radioButton';
import { RadioProps } from './interface';
export * from './interface'; export * from './interface';
interface CompoundedComponent
extends React.ForwardRefExoticComponent<RadioProps & React.RefAttributes<HTMLElement>> {
Group: typeof Group;
Button: typeof Group;
}
const Radio = InternalRadio as CompoundedComponent;
Radio.Button = Button; Radio.Button = Button;
Radio.Group = Group; Radio.Group = Group;
export { Button, Group }; export { Button, Group };

13
components/radio/radio.tsx

@ -1,19 +1,11 @@
import * as React from 'react'; import * as React from 'react';
import RcCheckbox from 'rc-checkbox'; import RcCheckbox from 'rc-checkbox';
import classNames from 'classnames'; import classNames from 'classnames';
import RadioGroup from './group';
import RadioButton from './radioButton';
import { RadioProps, RadioChangeEvent } from './interface'; import { RadioProps, RadioChangeEvent } from './interface';
import { ConfigContext } from '../config-provider'; import { ConfigContext } from '../config-provider';
import RadioGroupContext from './context'; import RadioGroupContext from './context';
import { composeRef } from '../_util/ref'; import { composeRef } from '../_util/ref';
interface CompoundedComponent
extends React.ForwardRefExoticComponent<RadioProps & React.RefAttributes<HTMLElement>> {
Group: typeof RadioGroup;
Button: typeof RadioButton;
}
const InternalRadio: React.ForwardRefRenderFunction<unknown, RadioProps> = (props, ref) => { const InternalRadio: React.ForwardRefRenderFunction<unknown, RadioProps> = (props, ref) => {
const context = React.useContext(RadioGroupContext); const context = React.useContext(RadioGroupContext);
const { getPrefixCls, direction } = React.useContext(ConfigContext); const { getPrefixCls, direction } = React.useContext(ConfigContext);
@ -60,10 +52,9 @@ const InternalRadio: React.ForwardRefRenderFunction<unknown, RadioProps> = (prop
); );
}; };
const Radio = React.forwardRef<unknown, RadioProps>(InternalRadio) as CompoundedComponent; const Radio = React.forwardRef<unknown, RadioProps>(InternalRadio);
Radio.displayName = 'Radio'; Radio.displayName = 'Radio';
Radio.Group = RadioGroup;
Radio.Button = RadioButton;
Radio.defaultProps = { Radio.defaultProps = {
type: 'radio', type: 'radio',
}; };

Loading…
Cancel
Save