Skip to content

Commit

Permalink
fix radio types (youzan#1055)
Browse files Browse the repository at this point in the history
  • Loading branch information
intellild authored and cpylua committed Apr 24, 2019
1 parent b198d0c commit b476da8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/zent/src/radio/AbstractRadio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface IRadioProps {
className?: string;
prefix?: string;
checked?: boolean;
onChange?: (e: IRadioEvent) => void;
onChange: (e: IRadioEvent) => void;
style?: React.CSSProperties;
}

Expand All @@ -42,7 +42,7 @@ abstract class AbstractRadio extends Component<IRadioProps> {

// event liftup
// link: https://facebook.github.io/react/docs/lifting-state-up.html
handleChange = evt => {
handleChange: React.ChangeEventHandler<HTMLInputElement> = evt => {
const { props, context } = this;
const e: IRadioEvent = {
target: {
Expand Down
48 changes: 29 additions & 19 deletions packages/zent/src/radio/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ import eq from 'lodash-es/eq';

import memoize from '../utils/memorize-one';
import GroupContext from './GroupContext';
import { IRadioEvent } from './AbstractRadio';

const GroupContextProvider = GroupContext.Provider;

export interface IGroupProps {
value: any;
disabled?: boolean;
readOnly?: boolean;
onChange: React.ChangeEventHandler<HTMLInputElement>;
isValueEqual?: (value1: any, value2: any) => boolean;
export interface IRadioGroupProps {
value: unknown;
disabled: boolean;
readOnly: boolean;
onChange: (e: IRadioEvent) => void;
isValueEqual: (value1: unknown, value2: unknown) => boolean;
className?: string;
prefix?: string;
style?: React.CSSProperties;
}

export class RadioGroup extends Component<IGroupProps> {
export class RadioGroup extends Component<IRadioGroupProps> {
static defaultProps = {
prefix: 'zent',
className: '',
Expand All @@ -31,15 +32,22 @@ export class RadioGroup extends Component<IGroupProps> {
onChange: noop,
};

getGroupContext = memoize((value, disabled, readOnly, isValueEqual) => ({
value,
disabled,
readOnly,
isValueEqual,
onRadioChange: this.onRadioChange,
}));
getGroupContext = memoize(
(
value: unknown,
disabled: boolean,
readOnly: boolean,
isValueEqual: (value1: unknown, value2: unknown) => boolean
) => ({
value,
disabled,
readOnly,
isValueEqual,
onRadioChange: this.onRadioChange,
})
);

onRadioChange = e => {
onRadioChange = (e: IRadioEvent) => {
this.props.onChange(e);
};

Expand All @@ -55,10 +63,12 @@ export class RadioGroup extends Component<IGroupProps> {
children,
} = this.props;

const classString = classNames({
[`${prefix}-radio-group`]: true,
[className]: !!className,
});
const classString = classNames(
{
[`${prefix}-radio-group`]: true,
},
className
);

return (
<GroupContextProvider
Expand Down

0 comments on commit b476da8

Please sign in to comment.