Skip to content

Commit

Permalink
Improved onChange type.
Browse files Browse the repository at this point in the history
  • Loading branch information
radekmie committed Feb 26, 2021
1 parent 94d48fc commit 63e4bac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/uniforms/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ export type GuaranteedProps<Value> = {
id: string;
label: ReactNode;
name: string;
onChange: (value: any, name?: string) => void;
onChange: OnChange<Value | undefined>;
placeholder: string;
readOnly: boolean;
showInlineError: boolean;
value?: Value;
};

type OnChange<Value> = {
(value: Value): void;
(value: any, name: string): void;
};

export type HTMLFieldProps<Value, Element, Extension = object> = FieldProps<
Value,
HTMLProps<Element>,
Expand Down
2 changes: 1 addition & 1 deletion website/pages-parts/CustomFields/CycleField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Cycle({
? allowedValues.indexOf(value) === allowedValues.length - 1
? required
? allowedValues[0]
: null
: undefined
: allowedValues[allowedValues.indexOf(value) + 1]
: allowedValues[0],
)
Expand Down
3 changes: 2 additions & 1 deletion website/pages-parts/CustomFields/RatingField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function Rating({
style={{ fontSize: 40, cursor: 'pointer' }}
key={index}
onClick={() =>
disabled || onChange(!required && value === index ? null : index)
disabled ||
onChange(!required && value === index ? undefined : index)
}
>
{index <= value ? '★' : '☆'}
Expand Down

0 comments on commit 63e4bac

Please sign in to comment.