Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit e972d94

Browse files
committed
fix(tags): initialvalues and playground documentation form
1 parent 540ae17 commit e972d94

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

src/components/Form/__stories__/Playground.stories.tsx

+29-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import type { ChangeEvent } from 'react'
44
import { useState } from 'react'
55
import {
66
CheckboxField,
7+
DateField,
78
Form,
9+
RadioField,
810
RichSelectField,
911
Submit,
1012
SubmitErrorAlert,
13+
TagsField,
1114
TextBoxField,
1215
} from '../..'
1316
import { emailRegex, mockErrors } from '../../../mocks/mockErrors'
@@ -17,7 +20,7 @@ export const Playground: ComponentStory<typeof Form> = args => {
1720

1821
return (
1922
<Form {...args}>
20-
<Stack gap={2}>
23+
<Stack gap={3}>
2124
<Checkbox
2225
checked={state}
2326
onChange={(event: ChangeEvent<HTMLInputElement>) =>
@@ -42,6 +45,20 @@ export const Playground: ComponentStory<typeof Form> = args => {
4245
required
4346
regex={[emailRegex]}
4447
/>
48+
<Stack gap={2} direction="row">
49+
<RadioField name="choice" value="1" required>
50+
1
51+
</RadioField>
52+
<RadioField name="choice" value="2">
53+
2
54+
</RadioField>
55+
<RadioField name="choice" value="3">
56+
3
57+
</RadioField>
58+
</Stack>
59+
60+
<DateField name="date" label="birthday" />
61+
4562
<RichSelectField
4663
multiple
4764
noTopLabel
@@ -55,6 +72,9 @@ export const Playground: ComponentStory<typeof Form> = args => {
5572
{ label: 'Devops', value: 'devops' },
5673
]}
5774
/>
75+
76+
<TagsField name="tags" placeholder="Tags..." tags={[]} />
77+
5878
<CheckboxField name="receiveEmailUpdates">
5979
I&apos;d like to receive news updates
6080
</CheckboxField>
@@ -67,5 +87,12 @@ export const Playground: ComponentStory<typeof Form> = args => {
6787

6888
Playground.args = {
6989
errors: mockErrors,
70-
initialValues: { receiveEmailUpdates: true },
90+
initialValues: {
91+
receiveEmailUpdates: true,
92+
choice: '2',
93+
tags: ['cloud', 'of', 'choice'],
94+
},
95+
onRawSubmit: values => {
96+
console.log('Submit', values)
97+
},
7198
}

src/components/TagsField/index.tsx

+16-8
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@ import type { ComponentProps } from 'react'
33
import { useFormField } from '../../hooks'
44
import type { BaseFieldProps } from '../../types'
55

6-
export type TagsFieldProps<T = unknown, K = string> = BaseFieldProps<T, K> &
6+
type TagsProp = ComponentProps<typeof Tags>['tags']
7+
8+
export type TagsFieldProps<T = TagsProp, K = string> = BaseFieldProps<T, K> &
79
Partial<
8-
Pick<ComponentProps<typeof Tags>, 'tags' | 'variant' | 'onChange'>
10+
Pick<
11+
ComponentProps<typeof Tags>,
12+
| 'tags'
13+
| 'variant'
14+
| 'onChange'
15+
| 'placeholder'
16+
| 'disabled'
17+
| 'className'
18+
| 'id'
19+
>
920
> & {
10-
className?: string
11-
disabled?: boolean
12-
id?: string
1321
name: string
14-
placeholder: string
1522
required?: boolean
1623
}
1724

@@ -27,11 +34,12 @@ export const TagsField = ({
2734
validate,
2835
variant,
2936
}: TagsFieldProps): JSX.Element => {
30-
const { input } = useFormField(name, {
37+
const { input } = useFormField<TagsProp>(name, {
3138
disabled,
3239
required,
3340
type: 'text',
3441
validate,
42+
value: tags,
3543
})
3644

3745
return (
@@ -46,7 +54,7 @@ export const TagsField = ({
4654
}}
4755
placeholder={placeholder}
4856
variant={variant}
49-
tags={tags}
57+
tags={input.value}
5058
/>
5159
)
5260
}

0 commit comments

Comments
 (0)