Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

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

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

Already on GitHub? Sign in to your account

[BUG] CreatableSelect with onCreateOption prop has a bug #46

Closed
t6adev opened this issue Feb 7, 2022 · 3 comments
Closed

[BUG] CreatableSelect with onCreateOption prop has a bug #46

t6adev opened this issue Feb 7, 2022 · 3 comments
Assignees
Labels
Bug Something isn't working Not Really a Bug Someone thought it was a bug, but turns out its not a bug

Comments

@t6adev
Copy link

t6adev commented Feb 7, 2022

Describe the bug
If you use CreatableSelect with onCreateOption, <CreatableSelect onCreateOption={...} /> to create a new option, the created value is not displayed.

Link to Reproduction
https://codesandbox.io/s/chakra-react-select-oncreateoption-cy2ko

You can confirm that react-select has no problem with that.
https://codesandbox.io/s/z19sm
https://react-select.com/creatable

To Reproduce
Steps to reproduce the behavior:

  1. Go to the reproduction link
  2. Type anything to create an option then enter
  3. The inputted value is not displayed

Expected behavior
The created value should be displayed.

Thanks.

@csandman
Copy link
Owner

csandman commented Feb 7, 2022

So if you look at the documentation for that prop, this is what it says:

onCreateOption


If provided, this will be called with the input value when a new option is created, and onChange will not be called. Use this when you need more control over what happens when new options are created.

(inputValue:string) => void

https://react-select.com/props#creatable-props

So this means that if you use this option, you will have to implement some manual code for setting the option. If you look at the code in the example you provided for the original package, you'll see that in their onCreateOption function they're handling how the new value is being set on the select.

I made a modified version of the chakra-react-select demo you made implementing all of the code from the original example, and it works in the same way: https://codesandbox.io/s/chakra-react-select-oncreateoption-forked-q7703?file=/app.tsx

Let me know if this solves your issue!

@t6adev
Copy link
Author

t6adev commented Feb 8, 2022

Oh, So sorry for bothering you, it's my fault.
I didn't confirm the doc and my shared code carefully.

I also re-implemented my sample code then it works well.
https://codesandbox.io/s/chakra-react-select-oncreateoption-cy2ko?file=/app.tsx

Thank you so much for taking your time.

@t6adev t6adev closed this as completed Feb 8, 2022
@csandman
Copy link
Owner

csandman commented Feb 8, 2022

No worries, glad I could help!

@csandman csandman added Bug Something isn't working Not Really a Bug Someone thought it was a bug, but turns out its not a bug labels Feb 8, 2022
Repository owner locked and limited conversation to collaborators May 5, 2022
@csandman csandman converted this issue into discussion #112 May 5, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Bug Something isn't working Not Really a Bug Someone thought it was a bug, but turns out its not a bug
Projects
None yet
Development

No branches or pull requests

2 participants