Skip to content

Commit 37a3ada

Browse files
fix: resolve Mantine package bugs and improve functionality (#147)
1 parent 98f61f9 commit 37a3ada

File tree

10 files changed

+114
-61
lines changed

10 files changed

+114
-61
lines changed

apps/web/components/utils.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const zodFormSchema = z.object({
7070
},
7171
})
7272
),
73-
favouriteNumber: z
73+
favouriteNumber: z.coerce
7474
.number({
7575
invalid_type_error: "Favourite number must be a number.",
7676
})
@@ -123,16 +123,16 @@ const zodFormSchema = z.object({
123123
country: z.string().optional(),
124124
test: z.object({
125125
name: z.string(),
126-
age: z.number(),
126+
age: z.coerce.number(),
127127
test: z.object({
128128
name: z.string(),
129-
age: z.number(),
129+
age: z.coerce.number(),
130130
test: z.object({
131131
name: z.string(),
132-
age: z.number(),
132+
age: z.coerce.number(),
133133
test: z.object({
134134
name: z.string(),
135-
age: z.number(),
135+
age: z.coerce.number(),
136136
}),
137137
}),
138138
}),
@@ -145,16 +145,16 @@ const zodFormSchema = z.object({
145145
// country: z.string().optional(),
146146
// test: z.object({
147147
// name: z.string(),
148-
// age: z.number(),
148+
// age: z.coerce.number(),
149149
// test: z.object({
150150
// name: z.string(),
151-
// age: z.number(),
151+
// age: z.coerce.number(),
152152
// test: z.object({
153153
// name: z.string(),
154-
// age: z.number(),
154+
// age: z.coerce.number(),
155155
// test: z.object({
156156
// name: z.string(),
157-
// age: z.number(),
157+
// age: z.coerce.number(),
158158
// }),
159159
// }),
160160
// }),

apps/web/cypress/component/autoform/mantine-zod/advanced-features.cy.tsx

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { AutoForm } from "@autoform/mui";
2+
import { AutoForm } from "@autoform/mantine";
33
import { ZodProvider, fieldConfig } from "@autoform/zod";
44
import { z } from "zod";
55
import { TestWrapper } from "./utils";
@@ -59,16 +59,19 @@ describe("AutoForm Advanced Features Tests", () => {
5959
</TestWrapper>
6060
);
6161

62-
cy.get(".MuiFormControl-root")
62+
cy.get(".mantine-InputWrapper-root")
6363
.eq(0)
6464
.find("input")
6565
.should("have.attr", "name", "username");
66-
cy.get(".MuiFormControl-root")
66+
cy.get(".mantine-InputWrapper-root")
6767
.eq(1)
6868
.find("input")
6969
.should("have.attr", "name", "password");
70-
cy.get(".MuiFormControl-root").eq(2).find(".MuiSelect-select");
71-
cy.get(".MuiFormControl-root")
70+
cy.get(".mantine-InputWrapper-root")
71+
.eq(2)
72+
.find(".mantine-Select-wrapper")
73+
.find("input");
74+
cy.get(".mantine-InputWrapper-root")
7275
.eq(3)
7376
.find("input")
7477
.should("have.attr", "name", "bio");
@@ -119,14 +122,14 @@ describe("AutoForm Advanced Features Tests", () => {
119122
</TestWrapper>
120123
);
121124

122-
cy.get('.MuiSelect-select[aria-labelledby*="favoriteColor"]').should(
123-
"exist"
124-
);
125-
cy.get('.MuiSelect-select[aria-labelledby*="favoriteColor"]').click();
126-
cy.get('.MuiMenu-list[role="listbox"] .MuiMenuItem-root').should(
127-
"have.length",
128-
3
129-
);
125+
cy.get(".mantine-Select-input").eq(0).click();
126+
127+
cy.get(".mantine-Popover-dropdown").within(() => {
128+
cy.contains("red").should("exist");
129+
cy.contains("green").should("exist");
130+
cy.contains("blue").should("exist");
131+
});
132+
// mantine select fields portal has auto-generated aria-label and names.
130133
});
131134

132135
it("renders textarea field correctly", () => {

packages/mantine/CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# @autoform/mantine
22

3+
## 2.3.1
4+
5+
### Patch Changes
6+
7+
- - fixed description not showing in mantine package
8+
- fixed select not working properly
9+
- added mantine styles to date picker
10+
- corrected key props via spread
11+
- supported default value for date field (e.g. `birthdate: "1990-01-01" as unknown as Date,`)
12+
313
## 2.3.0
414

515
### Minor Changes

packages/mantine/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@autoform/mantine",
3-
"version": "2.3.0",
3+
"version": "2.3.1",
44
"main": "./dist/index.js",
55
"module": "./dist/index.mjs",
66
"types": "./dist/index.d.ts",

packages/mantine/src/components/BooleanField.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ import { AutoFormFieldProps } from "@autoform/react";
55
export const BooleanField: React.FC<AutoFormFieldProps> = ({
66
inputProps,
77
label,
8-
}) => <Checkbox label={label} {...inputProps} />;
8+
}) => {
9+
const { key, ...props } = inputProps;
10+
11+
return <Checkbox label={label} key={key} {...props} />;
12+
};

packages/mantine/src/components/DateField.tsx

+25-18
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,28 @@ export const DateField: React.FC<AutoFormFieldProps> = ({
66
field,
77
inputProps,
88
label,
9-
}) => (
10-
<DateInput
11-
label={label}
12-
description={field.description}
13-
error={inputProps.error}
14-
onChange={(value) => {
15-
// react-hook-form expects an event object
16-
const event = {
17-
target: {
18-
name: field.key,
19-
value: value?.toISOString(),
20-
},
21-
};
22-
inputProps.onChange(event);
23-
}}
24-
value={inputProps.value}
25-
/>
26-
);
9+
value
10+
}) => {
11+
const { key, ...props } = inputProps;
12+
13+
return (
14+
<DateInput
15+
key={key}
16+
{...props}
17+
label={label}
18+
description={field.fieldConfig?.description}
19+
error={inputProps.error}
20+
onChange={(value) => {
21+
// react-hook-form expects an event object
22+
const event = {
23+
target: {
24+
name: field.key,
25+
value: value?.toISOString(),
26+
},
27+
};
28+
inputProps.onChange(event);
29+
}}
30+
defaultValue={value ? new Date(value) : undefined}
31+
/>
32+
);
33+
};

packages/mantine/src/components/Form.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react";
2+
import '@mantine/dates/styles.css';
23
import { Box } from "@mantine/core";
34

45
export const Form = React.forwardRef<

packages/mantine/src/components/NumberField.tsx

+13-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ export const NumberField: React.FC<AutoFormFieldProps> = ({
66
field,
77
inputProps,
88
label,
9-
}) => (
10-
<TextInput
11-
type="number"
12-
label={label}
13-
description={field.description}
14-
{...inputProps}
15-
/>
16-
);
9+
}) => {
10+
const { key, ...props } = inputProps;
11+
12+
return (
13+
<TextInput
14+
key={key}
15+
type="number"
16+
label={label}
17+
description={field.fieldConfig?.description}
18+
{...props}
19+
/>
20+
);
21+
};

packages/mantine/src/components/SelectField.tsx

+29-9
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,32 @@ export const SelectField: React.FC<AutoFormFieldProps> = ({
77
error,
88
inputProps,
99
label,
10-
}) => (
11-
<Select
12-
error={error}
13-
label={label}
14-
data={(field.options || []).map(([key, label]) => ({ value: key, label }))}
15-
description={field.description}
16-
{...inputProps}
17-
/>
18-
);
10+
id,
11+
value,
12+
}) => {
13+
const { key, ...props } = inputProps;
14+
15+
return (
16+
<Select
17+
key={key}
18+
{...props}
19+
label={label}
20+
error={error}
21+
onChange={(value) => {
22+
const event = {
23+
target: {
24+
name: field.key,
25+
value: value,
26+
},
27+
};
28+
props.onChange(event);
29+
}}
30+
defaultValue={value}
31+
description={field.fieldConfig?.description}
32+
data={(field.options || []).map(([key, label]) => ({
33+
value: key,
34+
label,
35+
}))}
36+
/>
37+
);
38+
};

packages/mantine/src/components/StringField.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ export const StringField: React.FC<AutoFormFieldProps> = ({
88
label,
99
id,
1010
}) => {
11+
const { key, ...props } = inputProps;
12+
1113
return (
1214
<TextInput
1315
id={id}
16+
key={key}
1417
label={label}
15-
description={field.description}
16-
{...inputProps}
18+
description={field.fieldConfig?.description}
19+
{...props}
1720
/>
1821
);
1922
};

0 commit comments

Comments
 (0)