react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Creatable doesn't work with getOptionValue and getOptionLabel props

Open jdavidferreira opened this issue 6 years ago • 6 comments

When using Creatable component with getOptionValue and getOptionLabel props, the functionality to create new options does not work.

creatable_issue

Sandbox simple example here: https://codesandbox.io/s/creatable-custom-label-value-xr63g

The current workarround I'm using is to map the options to { label, value } format:

options.map( opt => ({ label: opt.name, value: opt.id }) )

jdavidferreira avatar Jan 12 '20 01:01 jdavidferreira

Using getNewOptionData fixed this for me.

kpatient avatar Jan 23 '20 13:01 kpatient

Hello -

In an effort to sustain the react-select project going forward, we're closing old issues.

We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our efforts towards the current major version.

If you aren't using the latest version of react-select please consider upgrading to see if it resolves any issues you're having.

However, if you feel this issue is still relevant and you'd like us to review it - please leave a comment and we'll do our best to get back to you!

bladey avatar May 28 '20 04:05 bladey

I'm using version 5.2.2 and the problem persists. Duplicate of https://github.com/JedWatson/react-select/issues/2630 https://github.com/JedWatson/react-select/issues/3417 https://github.com/JedWatson/react-select/issues/3941

claudiutamas avatar Apr 05 '22 12:04 claudiutamas

should be re-opened, still happens

chiptus avatar Apr 19 '22 16:04 chiptus

As already mentioned above using getNewOptionData fixes the issue. Standard implementation of an option is { label, value }. If you use a custom option schema then you should also update the created option with this schema using the getNewOptionData prop.

<Creatable 
   getOptionValue={({ id }) => id}
   getOptionLabel={({ name }) => name}
   getNewOptionData={(value, label) => ({ id: value, label: label, __isNew__: true })}
/>

A re-opening of this issue is not necessary.

Rall3n avatar Jun 20 '22 14:06 Rall3n

Thanks for your answer @Rall3n. While the answer helped to solve the issue, It takes a greate amount of time to debug and fix the issue to getOptionLabel and getOptionValue. Adding some coments in documentation should work.

jaiganesh-i2i avatar Oct 18 '23 10:10 jaiganesh-i2i