-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Control field validation behaviour #74
Changes from 1 commit
1e9c209
713bf2a
8d87e6e
1c61ef5
8b43442
96ba257
5f13b5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import {Meta, StoryObj} from '@storybook/react'; | ||
import {expect, userEvent, within} from '@storybook/test'; | ||
import {z} from 'zod'; | ||
|
||
import {withFormik, withRenderSettingsProvider} from '@/sb-decorators'; | ||
|
||
|
@@ -68,7 +69,7 @@ export const ValidationError: Story = { | |
}, | ||
}; | ||
|
||
export const NoAsterisks = { | ||
export const NoAsterisks: Story = { | ||
name: 'No asterisk for required', | ||
decorators: [withRenderSettingsProvider], | ||
parameters: { | ||
|
@@ -82,3 +83,33 @@ export const NoAsterisks = { | |
isRequired: true, | ||
}, | ||
}; | ||
|
||
export const ValidateOnBlur: Story = { | ||
args: { | ||
name: 'validateOnBlur', | ||
label: 'Validate on blur', | ||
}, | ||
parameters: { | ||
formik: { | ||
initialValues: { | ||
validateOnBlur: '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formik doesn't seem involved with the validating. So, should this parameter just be removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay - I understand the confusion!
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah hahaha, okay yeah that makes sense 😅 |
||
}, | ||
zodSchema: z.object({ | ||
validateOnBlur: z.any().refine(() => false, {message: 'Always invalid'}), | ||
}), | ||
}, | ||
}, | ||
play: async ({canvasElement}) => { | ||
const canvas = within(canvasElement); | ||
const input = await canvas.findByLabelText('Validate on blur'); | ||
expect(input).not.toHaveAttribute('aria-invalid'); | ||
|
||
await userEvent.type(input, 'foo'); | ||
expect(input).toHaveFocus(); | ||
expect(input).not.toHaveAttribute('aria-invalid'); | ||
|
||
input.blur(); | ||
expect(await canvas.findByText('Always invalid')).toBeVisible(); | ||
expect(input).toHaveAttribute('aria-invalid', 'true'); | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not be set by the context parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've hardcoded them to reflect the actual implementation because enabling this validates the whole form rather than just the field that's touched.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh check, got it