-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overriding fields #226
Comments
Yeah, component libs that do not match 1:1 the HTML tags in their components are trickier to integrate. That said, some people managed to do a decent job using renderField + useField + useFormState. Personally, I'd advise using Remix Forms with libs that have a 1:1 correlation with HTML, otherwise it might be too cumbersome. At least until we devise a more flexible API :) we're very open to ideas! I'll leave this issue open for that reason. |
I was able to solve this particular case using const FormInputField = React.forwardRef<HTMLInputElement, InputProps>(
(props, ref) => {
const { label } = useField()
return (
<Input
ref={ref}
{...props}
label={label}
/>
)
}
)
FormInputField.displayName = 'FormInputField'
const EmptyComponent = () => null
export function MyForm() {
return (
<Form
schema={schema}
labelComponent={EmptyComponent}
inputComponent={FormInputField}
>
<Field name="firstName" label="First name" /> If desired, you can also use |
So remix-forms allows overriding fields in a number of ways, but its API is still crusty if one wants to integrate a different UI library with it. Let's focus on the example of using NextUI: In NextUI the Input component expects the label as prop. In this case remix-forms allows the following overrides:
This works fine, but it's tedious when all the fields have to be overridden in all forms. Now, one can also override the input component:
Turns out that because remix-forms assumes the label is a different react component, not just a string, the label is not passed down to the custom input component. Needless to say, overriding the Label component is useless, which leaves us with overriding the Field component.
Now the issue is that the label is a component passed down to the custom field component as children, so accessing its props is a clumsy thing to do.
Maybe I'm missing something, but it would be nice to have a simpler way to override a full component, with plain (no components) props.
The text was updated successfully, but these errors were encountered: