Skip to content

Commit 391edfd

Browse files
committed
fix: fields with checked not working correctly
1 parent f73e621 commit 391edfd

24 files changed

+29
-79
lines changed

src/Checkbox/Checkbox.stories.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ export const Primary: Story = {
2525
parameters: {
2626
form: {
2727
defaultValues: {
28-
test: false,
29-
},
30-
onSubmit: (data: any) => {
31-
console.log(data);
28+
test: true,
3229
},
3330
},
3431
},

src/Checkbox/Checkbox.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export function Checkbox<T extends FieldValues>({
2222
shouldUnregister,
2323
...mantineProps
2424
}: CheckboxProps<T>) {
25-
const { field, fieldState } = useController<T>({
25+
const {
26+
field: { value, ...field },
27+
fieldState,
28+
} = useController<T>({
2629
name,
2730
control,
2831
defaultValue,
@@ -31,7 +34,13 @@ export function Checkbox<T extends FieldValues>({
3134
});
3235

3336
return (
34-
<$Checkbox error={fieldState.error?.message} {...field} {...mantineProps} />
37+
<$Checkbox
38+
error={fieldState.error?.message}
39+
value={value}
40+
checked={value}
41+
{...field}
42+
{...mantineProps}
43+
/>
3544
);
3645
}
3746

src/Chip/Chip.stories.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ export const Primary: Story = {
2020
defaultValues: {
2121
test: false,
2222
},
23-
onSubmit: (data: any) => {
24-
console.log(data);
25-
},
2623
},
2724
},
2825
};
@@ -44,9 +41,6 @@ export const ChipGroup: StoryGroup = {
4441
defaultValues: {
4542
test: ["react"],
4643
},
47-
onSubmit: (data: any) => {
48-
console.log(data);
49-
},
5044
},
5145
},
5246
};

src/Chip/Chip.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ export function Chip<T extends FieldValues>({
2222
shouldUnregister,
2323
...props
2424
}: ChipProps<T>) {
25-
const { field } = useController<T>({
25+
const {
26+
field: { value, ...field },
27+
} = useController<T>({
2628
name,
2729
control,
2830
defaultValue,
2931
rules,
3032
shouldUnregister,
3133
});
32-
return <$Chip {...field} {...props} />;
34+
return <$Chip value={value} checked={value} {...field} {...props} />;
3335
}
3436

3537
Chip.Group = <T extends FieldValues>({

src/ColorInput/ColorInput.stories.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ export const Primary: Story = {
1919
defaultValues: {
2020
test: "#C5D899",
2121
},
22-
onSubmit: (data: any) => {
23-
console.log(data);
24-
},
2522
},
2623
},
2724
};

src/ColorPicker/ColorPicker.stories.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ export const Primary: Story = {
1919
defaultValues: {
2020
test: "rgba(47, 119, 150, 0.7)",
2121
},
22-
onSubmit: (data: any) => {
23-
console.log(data);
24-
},
2522
},
2623
},
2724
};

src/FileInput/FileInput.stories.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ export const Primary: Story = {
2020
defaultValues: {
2121
test: undefined,
2222
},
23-
onSubmit: (data: any) => {
24-
console.log(data);
25-
},
2623
},
2724
},
2825
};

src/Input/Input.stories.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ export const Primary: Story = {
1818
defaultValues: {
1919
test: "",
2020
},
21-
onSubmit: (data: any) => {
22-
console.log(data);
23-
},
2421
},
2522
},
2623
};

src/JsonInput/JsonInput.stories.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ export const Primary: Story = {
2020
defaultValues: {
2121
test: "",
2222
},
23-
onSubmit: (data: any) => {
24-
console.log(data);
25-
},
2623
},
2724
},
2825
};

src/MultiSelect/MultiSelect.stories.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ export const Primary: Story = {
2929
defaultValues: {
3030
test: [],
3131
},
32-
onSubmit: (data: any) => {
33-
console.log(data);
34-
},
3532
},
3633
},
3734
};

0 commit comments

Comments
 (0)