Modify injected Field input prop change function arguments

Add tests for input prop
This commit is contained in:
Alex Young
2017-08-23 17:05:36 +01:00
parent 8fa336c4a9
commit 1a85faf9f2
2 changed files with 25 additions and 9 deletions

View File

@@ -16,13 +16,21 @@ export type Formatter = (value: any, name: string) => any;
export type Parser = (value: any, name: string) => any;
export type Validator = (value: any, allValues?: any, props?: any) => any;
interface EventHandler<Event> {
(event: Event): void;
}
interface EventOrValueHandler<Event> extends EventHandler<Event> {
(value: any): void;
}
interface CommonFieldProps {
name: string;
onBlur: EventOrValueHandler<FocusEvent<any>>;
onChange: EventOrValueHandler<ChangeEvent<any>>;
onDragStart: EventOrValueHandler<DragEvent<any>>;
onDrop: EventOrValueHandler<DragEvent<any>>;
onFocus: EventOrValueHandler<FocusEvent<any>>;
onDragStart: EventHandler<DragEvent<any>>;
onDrop: EventHandler<DragEvent<any>>;
onFocus: EventHandler<FocusEvent<any>>;
}
interface BaseFieldProps<P = {}> extends Partial<CommonFieldProps> {
@@ -60,11 +68,6 @@ interface WrappedFieldProps {
meta: WrappedFieldMetaProps;
}
interface EventOrValueHandler<Event> {
(event: Event): void;
(value: any, newValue: any, previousValue: any): void;
}
interface WrappedFieldInputProps extends CommonFieldProps {
checked?: boolean;
value: any;

View File

@@ -96,7 +96,20 @@ const MyField: StatelessComponent<MyFieldProps> = ({
children,
input,
meta
}) => null;
}) => {
input.onBlur("value");
input.onBlur({} as React.SyntheticEvent<HTMLDivElement>);
input.onChange("value");
input.onChange({} as React.SyntheticEvent<HTMLDivElement>);
input.onDragStart({} as React.DragEvent<HTMLDivElement>);
input.onDrop({} as React.DragEvent<HTMLDivElement>);
input.onFocus({} as React.FocusEvent<HTMLDivElement>);
return null;
};
const FieldCustom = Field as new () => GenericField<MyFieldCustomProps>;
const MyFieldImm: StatelessComponent<MyFieldProps> = ({