aranlucas / react-hook-form-mantine

React Hook Form bindings for Mantine components
https://aranlucas.github.io/react-hook-form-mantine/
90 stars 12 forks source link

Chip Group not working correctly #5

Closed angelvega93 closed 1 year ago

angelvega93 commented 1 year ago

I am currently encountering an error while attempting to utilize the Chip Group functionality. The error message displayed is as follows:

Warning: Function components are not eligible for reference assignment. Any attempts to access this reference will result in failure. Perhaps you intended to use React.forwardRef()?

The example of the code being used:

<Chip.Group name="example" control={control}>
  <Chip.Item value="Test">React</Chip.Item>
</Chip.Group>

Additionally, within the example Storybook, is not possible to deselect. https://aranlucas.github.io/react-hook-form-mantine/?path=/story/components-chip--chip-group

aranlucas commented 1 year ago

Chip is an interesting component, but it looks like my example was wrong.

Passing in the prop "multiple" seems to have fixed it in my example.

<Chip.Group multiple>
  <Group position="center" mt="md">
    <Chip value="1">Multiple chips</Chip>
    <Chip value="2">Can be selected</Chip>
    <Chip value="3">At a time</Chip>
  </Group>
</Chip.Group>

Can you check to see if that fixes it for you too?

aranlucas commented 1 year ago

https://github.com/mantinedev/mantine/blob/master/src/mantine-core/src/Chip/ChipGroup/ChipGroup.tsx

You might get a type error with adding the prop multiple={true}, but it will still work. Seeing if there's a better than to just change my type to

export type ChipGroupProps<T extends FieldValues> = UseControllerProps<T> &
  Omit<$ChipGroupProps<true>, "value" | "defaultValue">;
aranlucas commented 1 year ago

https://github.com/aranlucas/react-hook-form-mantine/pull/6/files

This was my best attempt at fixing the type issue. Let me know if that looks okay and I can go ahead and merge + release

angelvega93 commented 1 year ago

Now works flawlessly, thanks.

aranlucas commented 1 year ago

Released https://github.com/aranlucas/react-hook-form-mantine/releases/tag/v1.0.10

Added ChipGroup example to https://codesandbox.io/s/react-hook-mantine-krflqj?file=/src/App.tsx

ref issue should also be fixed