I'm using the radix ui primitive Select, but i don't know how to integrate it with React Hook Form. I've tried putting the register in the Select.Root tag but it didn't work.
I'm also using Styled Components so all the Select tags are used like <S.Something/> because i've imported all as S
This is the function that creates the item:
const SelectItem = React.forwardRef(({ children, ...props } : any, forwardedRef) => {
return (
<S.Item {...props} ref={forwardedRef}>
<S.ItemText>{children}</S.ItemText>
<S.ItemIndicator>
<S.TriggerIcon src="/form/selector-icon.svg" />
</S.ItemIndicator>
</S.Item>
);
});
Then i create the Select this way:
<S.FormItem key={index}>
<S.Label htmlFor={index+''}>{question.question}</S.Label>
<S.Root {...register(`${questionName}`, { required: true })}>
<S.Trigger id={index+''}>
<S.Value/>
<S.Icon>
<S.TriggerIcon src="/form/selector-icon.svg" />
</S.Icon>
</S.Trigger>
<S.Portal>
<S.Content>
<S.SelectorUp>
Up
</S.SelectorUp>
<S.Viewport>
{question.options?.map((option, i) => {
return (
<SelectItem key={i} value={option}>
{option}
</SelectItem>
)
})}
</S.Viewport>
<S.SelectorDown>
Down
</S.SelectorDown>
</S.Content>
</S.Portal>
</S.Root>
</S.FormItem>