ui icon indicating copy to clipboard operation
ui copied to clipboard

any idea how can I extend the FormMessage to localise the error message?

Open huangfulei opened this issue 1 year ago • 0 comments

Here is my thought:

Solution 1: pass i18n to the component const FormMessage = React.forwardRef< HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>

(({ className, i18n, children, ...props }, ref) => { const { error, formMessageId } = useFormField(); const body = error ? String(error?.message) : children; const localisedBody = i18n.exists(body) ? i18n.t(body) : body;

...

Solution 2: prioritize "children" so we can pass localized children from the parent component. const FormMessage = React.forwardRef< HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>

(({ className, children, ...props }, ref) => { const { error, formMessageId } = useFormField(); // const body = error ? String(error?.message) : children; const body = children ? children: String(error?.message);

huangfulei avatar May 26 '23 11:05 huangfulei