Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

type prop returned from the getCollectionProps helper is widened #561

Closed
AMEH64 opened this issue Apr 2, 2024 · 0 comments · Fixed by #562
Closed

type prop returned from the getCollectionProps helper is widened #561

AMEH64 opened this issue Apr 2, 2024 · 0 comments · Fixed by #562

Comments

@AMEH64
Copy link
Contributor

AMEH64 commented Apr 2, 2024

Describe the bug and the expected behavior

The getCollectionProps widens the type prop from 'checkbox' | 'radio' to 'checkbox' | 'color' | 'date' | 'datetime-local' | 'email' | 'file' | 'hidden' | 'month' | 'number' | 'password' | 'radio' | 'range' | 'search' | 'tel' | 'text' | 'time' | 'url' | 'week'. This causes a type error to be raised when the props are passed to a custom input component that requires the type prop to be narrowed to 'checkbox', 'radio', or a combination of the two.

Conform version

v1.0.6

Steps to Reproduce the Bug or Issue

  1. Create a custom input component to encapsulate the styles of a checkbox/radio input. Narrow the type property for the component to 'checkbox' | 'radio'.

    const CheckboxCard = React.forwardRef<
      HTMLInputElement,
      Omit<React.ComponentPropsWithoutRef<'input'>, 'type'> & {
        label: React.ReactNode
        type: Extract<React.HTMLInputTypeAttribute, 'checkbox' | 'radio'>
      }
    >(({ className, label, ...props }, ref) => (
      <label className={classNames(className, '...')}>
        <span>{label}</span>
        <input {...props} className="peer sr-only" />
        <CheckCircleIcon className="size-4 opacity-0 transition-opacity peer-checked:opacity-100" />
      </label>
    ))
    CheckboxCard.displayName = 'CheckboxCard'
  2. Wire up the custom component using getCollectionProps.

    const Example = () => {
      const [meta, _form] = useField('fieldName')
    
      return (
        <Fieldset>
          <Legend>A checkbox field.</Legend>
          {getCollectionProps(meta, {
            type: 'checkbox',
            options: ['one', 'two', 'three'],
          }).map(props => (
            <CheckboxCard label={props.value} {...props} />
          ))}
        </Fieldset>
      )
    }
  3. Observe the type error.

    image

What browsers are you seeing the problem on?

No response

Screenshots or Videos

No response

Additional context

No response

@AMEH64 AMEH64 changed the title type prop is widened from getCollectionProps type prop returned from the getCollectionProps helper is widened Apr 2, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant