Skip to content

Solid: General Ref Type #285

Open
Open
@alfianandinugraha

Description

@alfianandinugraha

If the purpose of FieldElement is only to focus an element, then it should work this way, right?

I created an example of custom ref type https://stackblitz.com/edit/solidjs-templates-opswh6tl?file=src%2FApp.tsx (there is error ref type) In this example, the Input component receives a ref with only a focus method, and it still works. When an error occurs, the input element correctly receives focus.

Perhaps we can make FieldElement like this:

export type FieldElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | {
    focus: () => void;
}

Or simply

// If we using this, maybe we can extend the library into non-web environment such as React Native
export type FieldElement = {
    focus: () => void;
}

In React Hook Form the library using ref like that so we can manage ref from the Input element as long as the ref accept focus() and blur() methods (RHF also works on React Native)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions