Skip to content

Implementing a select component with conform #376

Answered by edmundhung
lewisblackburn asked this question in Q&A
Discussion options

You must be logged in to vote

The issue here is caused by the name props passed to the <SelectTrigger /> when you spread the buttonProps on it. This makes both the button element and select element having the same name set and so it fails to get a correct ref when you do buttonRef.current?.form?.elements.namedItem(buttonProps.name ?? ''). It would be easier to spot this if Conform can warn about it.

To fix it, just pick the name prop out of the buttonProps:

export function SelectField() {
  // ...
  const { name, ...props } = buttonProps;

  return (
    <div className={className}>
      <Label htmlFor={id} {...labelProps} />
      <Select name={buttonProps.name} open={open} onOpenChange={setOpen} aria-invalid={true}>

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@cr101
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by lewisblackburn
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants