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

Removing completely the create new option label

Open junibrosas opened this issue 9 years ago • 7 comments

The library is very cool and very customisable. I am having a hard time removing completely the "Create option 'x'" label. I can use promptTextCreator={(label) => ''} but there is still empty tag remain. I want to completely remove the label but still able to add new option via key down.

junibrosas avatar Feb 09 '17 12:02 junibrosas

How about:

promptTextCreator={(label) => undefined}

sandinosaso avatar Mar 16 '17 14:03 sandinosaso

@sandinosaso It didn't work to. Still a "empty" space in the selects

problema_select

joaoeffting avatar Apr 06 '17 21:04 joaoeffting

Hey @joaoeffting and @junibrosas,

I have found a solution for this problem, it's a workaround.

<Select.Creatable
  onChange={this.onChange}
  promptTextCreator={() => false}
  newOptionCreator={({ label, labelKey, valueKey }) => {
    const show = !label

    const option = {}
    option[valueKey] = label
    option[labelKey] = label
    option.className = classnames(
      'Select-create-option-placeholder',
      [styles.hide_placeholder]: show,
    )
    return option
  }}
  value={this.props}
  options={this.props.options}
  isLoading={this.props.fetching}
  labelKey="name"
  valueKey="id"
/>
.hide_placeholder {
  display: none !important;
}

The main trick is:

  • First set the promptTextCreator to return false:
  promptTextCreator={() => false}
  • And after, define a newOptionCreator to handle that option, like so:
  newOptionCreator={({ label, labelKey, valueKey }) => {
    const show = !label

    const option = {}
    option[valueKey] = label
    option[labelKey] = label
    option.className = classnames(
      'Select-create-option-placeholder',
      [styles.hide_placeholder]: show,
    )
    return option
  }}

It's still a thick line, but someone could improve this. My css skills are limited.

brunoarueira avatar May 05 '17 13:05 brunoarueira

@brunoarueira I simply used this to disable (not show) the promptTextCreator:

.Select-create-option-placeholder {
  display: none;
}

Not sure why you need to use newOptionCreator for this because the promptTextCreator has a uniq css class with .Select-create-option-placeholder that can be used for this.

jnachtigall avatar Jan 09 '18 12:01 jnachtigall

@jnachtigall Great, when I return to the feature which uses the react-select I'll try your suggestion! Thanks, btw

brunoarueira avatar Jan 09 '18 12:01 brunoarueira

You can just use isValidNewOption={() => false}

bbinoy avatar Jan 18 '18 18:01 bbinoy

You can just use isValidNewOption={() => false}

I'm really confused about why this solution is so well received. This doesn't merely hide the create label, it completely disables the create functionality....if you don't want the create functionality, then why would you even be using Creatable in the first place?

I'm still struggling to find a way to hide the create label in the dropdown without completely breaking all functionality.

dwightware4 avatar Nov 11 '20 20:11 dwightware4