Skip to content

Commit

Permalink
fix: allow for jsx elements on field error message (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
chadbrokaw authored Aug 29, 2024
1 parent 4533ac0 commit b1a1de8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/forms/Field.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ export const TextFieldError = () => {
)
}

export const TextFieldErrorElement = () => {
const { register } = useForm({ mode: "onChange" })
return (
<Field
register={register}
name={"Test Input"}
label={"Custom label"}
type={"text"}
error={true}
errorMessage={<div className="font-bold italic">Custom error message as element</div>}
/>
)
}

export const CurrencyField = () => {
const { register, getValues, setValue } = useForm({ mode: "onChange" })
return (
Expand Down
2 changes: 1 addition & 1 deletion src/forms/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { httpsRegex, urlRegex } from "../helpers/validators"

export interface FieldProps {
error?: boolean
errorMessage?: string
errorMessage?: string | JSX.Element
className?: string
controlClassName?: string
caps?: boolean
Expand Down

0 comments on commit b1a1de8

Please sign in to comment.