Skip to content

Commit 8ff8fb2

Browse files
committed
feat(form): enhance error message positioning and update form field styling in FormInput and FormSelect components
1 parent b689b12 commit 8ff8fb2

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

web/src/components/form/form-input.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as Form from '@radix-ui/react-form';
22
import { useFormContext } from 'react-hook-form';
33
import { FormFieldProps } from '../../types/form.types';
44
import { getNestedValue } from '@/lib/helper';
5+
import { cn } from '@/lib/utils';
56

67
export const FormInput = ({ name, label, error, ...props }: FormFieldProps) => {
78
const {
@@ -13,7 +14,12 @@ export const FormInput = ({ name, label, error, ...props }: FormFieldProps) => {
1314
const errorMessage = fieldError?.message as string;
1415

1516
return (
16-
<Form.Field className="form-field" name={name}>
17+
<Form.Field
18+
className={cn('form-field relative', {
19+
'mb-6': errorMessage,
20+
})}
21+
name={name}
22+
>
1723
{label && (
1824
<div className="mb-2 flex items-baseline justify-between">
1925
<Form.Label className="form-label">{label} :</Form.Label>
@@ -27,9 +33,11 @@ export const FormInput = ({ name, label, error, ...props }: FormFieldProps) => {
2733
/>
2834
</Form.Control>
2935
{errorMessage && (
30-
<Form.Message className="form-message ml-auto text-sm text-red-500">
31-
{errorMessage}
32-
</Form.Message>
36+
<div className="absolute left-0 top-full">
37+
<Form.Message className="form-message ml-auto text-sm text-red-500">
38+
{errorMessage}
39+
</Form.Message>
40+
</div>
3341
)}
3442
</Form.Field>
3543
);

web/src/components/form/form-select.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Select from 'react-select';
66
import { getNestedValue } from '@/lib/helper';
77
import { selectStyle } from '@/pages/helm-template/styles/helm-template.style';
88
import { useStyle } from '@/hooks';
9+
import { cn } from '@/lib/utils';
910

1011
interface OptionType {
1112
value: string;
@@ -38,7 +39,12 @@ export const FormSelect = ({
3839
const errorMessage = fieldError?.message as string;
3940

4041
return (
41-
<Form.Field className="form-field" name={name}>
42+
<Form.Field
43+
className={cn('form-field relative', {
44+
'mb-6': errorMessage,
45+
})}
46+
name={name}
47+
>
4248
{label && (
4349
<div className="mb-2 flex items-baseline justify-between">
4450
<Form.Label className="form-label">{label} :</Form.Label>
@@ -61,9 +67,11 @@ export const FormSelect = ({
6167
/>
6268
</Form.Control>
6369
{errorMessage && (
64-
<Form.Message className="form-message mt-1 text-red-500">
65-
{errorMessage}
66-
</Form.Message>
70+
<div className="absolute left-0 top-full">
71+
<Form.Message className="form-message ml-auto text-sm text-red-500">
72+
{errorMessage}
73+
</Form.Message>
74+
</div>
6775
)}
6876
</Form.Field>
6977
);

web/src/pages/helm-template/helm-template.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const HelmTemplate: FC = () => {
9797
});
9898

9999
const body: HelmTemplateBody = {
100-
api_version: data.api_version,
100+
api_version: parseInt(data.api_version),
101101
pods: body_data,
102102
};
103103

@@ -320,7 +320,7 @@ export const PodEnvironmentFields: React.FC<PodEnvironmentFieldsProps> = ({
320320
<div className="grid grid-cols-2 gap-4">
321321
{fields.map((field, envIdx) => (
322322
<div
323-
className="flex items-center divide-x divide-gray-200 rounded-md border border-gray-200 dark:divide-gray-500 dark:border-gray-500"
323+
className="flex items-center divide-x divide-gray-200 rounded-md border border-gray-200 dark:divide-gray-500 dark:border-gray-500 [&>div]:mb-0"
324324
key={field.id}
325325
>
326326
<FormInput

0 commit comments

Comments
 (0)