-
-
Notifications
You must be signed in to change notification settings - Fork 62
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Mentioned in the SolidJS Discord earlier and was recommended to post about it here.
I'm trying to figure out a good way to separate out a reusable component for an X/Y position form field, something like so:
type MyForm = {
position: {
x: number
y: number
}
};
// template:
<Field of={myForm} name="position"
{field => (
// where `PositionInput` consists of 2 text inputs: one for x and another for y
<PositionInput {...field.props} value={field.value} />
)}
</Field>But with the above, I don't see how the onBlur, onInput, and onChange callbacks could be passed to 2 <input> elements.
So I've been trying an alternative approach, but here I'm unsure how to make the TS types behave correctly:
// Parent:
<Form of={myForm}>
<PositionField of={myForm} name="position" />
</Form>
// PositionField:
export function PositionField<T>(props: { of: FormState<T>, name: string }) {
return (
<Field of={props.of} name={`${props.name}.x`}> // throws: Type '`${string}.x`' is not assignable to type 'ValuePaths<T>'
{field => <input {...field.props) value={field.value} />}
</Field>
<Field of={props.of} name={`${props.name}.y`}>
{field => <input {...field.props) value={field.value} />}
</Field>
)
}In short, is there a recommendation on how to create reusable subforms?
taehee-wwtaehee-ww
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request