Skip to content

Commit

Permalink
Merge pull request #349 from storybookjs/form-error-state-hide
Browse files Browse the repository at this point in the history
FormErrorState: Allow outside control of error messages
  • Loading branch information
winkerVSbecks authored Apr 6, 2022
2 parents c1d6262 + 3a74afc commit 649576e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/components/FormErrorState.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,12 @@ PureMultipleErrors.args = {
blurredFieldIds: new Set(['input-1', 'input-2']),
children: Children,
};

export const PureMultipleErrorsSuppressed = (args: PureFormErrorStateProps) => (
<PureFormErrorState {...args} />
);
PureMultipleErrorsSuppressed.decorators = decorators;
PureMultipleErrorsSuppressed.args = {
...PureMultipleErrors.args,
suppressErrorMessages: true,
};
4 changes: 3 additions & 1 deletion src/components/FormErrorState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface FormErrorStateChildrenArgs {
export interface FormErrorStateProps {
onSubmit: Function;
children: (args: FormErrorStateChildrenArgs) => JSX.Element;
suppressErrorMessages: boolean;
}

export interface PureFormErrorStateProps extends FormErrorStateProps {
Expand All @@ -40,6 +41,7 @@ export interface PureFormErrorStateProps extends FormErrorStateProps {

export const PureFormErrorState = ({
children,
suppressErrorMessages,
onSubmit,
onMouseEnter,
onMouseLeave,
Expand All @@ -54,7 +56,7 @@ export const PureFormErrorState = ({
onFocus: () => onFocus(id),
onBlur: () => onBlur(id),
error: (value: string) => getError({ id, value, validate }),
suppressErrorMessage: !primaryFieldId || primaryFieldId !== id,
suppressErrorMessage: suppressErrorMessages || !primaryFieldId || primaryFieldId !== id,
});

return children({ getFormErrorFieldProps, onSubmit });
Expand Down

0 comments on commit 649576e

Please sign in to comment.