Skip to content

Commit

Permalink
feat: support props in form fields
Browse files Browse the repository at this point in the history
  • Loading branch information
christianmat committed Sep 26, 2024
1 parent e8d1067 commit ea45487
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-pumas-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@frigade/react": patch
---

Adds support for props in form fields
2 changes: 1 addition & 1 deletion packages/react/src/components/Form/FormStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function FormStep({
() =>
// @ts-expect-error TODO: Add type to step.fields
(step.fields?.filter(
(field: any) => fieldTypes[field.type] != null && field.id
(field: FormFieldData) => fieldTypes[field.type] != null && field.id
) as FormFieldData[]) ?? [],
[step.fields, fieldTypes]
)
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/components/Form/fields/BaseField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface BaseFieldProps extends FormFieldProps {
}

export function BaseField({ children, field, fieldData, fieldState }: BaseFieldProps) {
const { id, label, placeholder } = fieldData
const { id, label, placeholder, props } = fieldData
const { error } = fieldState

const fieldProps = {
Expand All @@ -27,6 +27,7 @@ export function BaseField({ children, field, fieldData, fieldState }: BaseFieldP
...styles.input,
'aria-invalid': !!error,
value: field.value ?? '',
...props,
}

return (
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface FormFieldData extends ValidationRules {
type: string
value?: string
multiple?: boolean
props?: Record<string, string | number | boolean | undefined>
// allow any other custom properties
[key: string]: any
}
Expand Down

0 comments on commit ea45487

Please sign in to comment.