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

How to set current value or how to enable edit of the selected tag?

Open AlexanderTserkovniy opened this issue 9 years ago • 33 comments

Hi guys,

  1. The question is simple how to set current value of the input? Like when I put focus there and see already written text.

  2. Or how to enable editing of the existing tag, that I could click and continue typing?

Thanks.

AlexanderTserkovniy avatar Feb 16 '17 08:02 AlexanderTserkovniy

This is critical for my application. I looked into 2 and couldn't find any options to do this and would greatly appreciate a workaround (couldn't come up with that either).

jayryemure avatar Feb 17 '17 17:02 jayryemure

Is what you both are referring to is the ability to modify an existing selection's text, ie. Say the selected text is "AAAAA" and you want to select "AAAAB" you want to delete the last letter and change it... You can't. You have to delete the whole thing and start again?

If so, then I wholeheartedly agree, this seems like a really silly little bug... @JedWatson any ideas?

Siyfion avatar Feb 27 '17 12:02 Siyfion

@Siyfion yes, correct it is one option and another one is to set current value, thus we could remove element onclick and add set current value with focus, which will end with editing mode.

AlexanderTserkovniy avatar Feb 27 '17 12:02 AlexanderTserkovniy

@JedWatson I also need this for my application. Any ideas how can we implement it ?

mukulb90 avatar Mar 07 '17 12:03 mukulb90

This would be great to implement. Does maybe one of the 137 PRs of this writing solve this? Is it correctly understood that editing a selected value should only be possible if it is a Select.Creatable?

janusch avatar Aug 29 '17 14:08 janusch

I have this requirement too when the select is Creatable Ellipses are displayed on the field for long text but not able to place cursor pointer at the end. Not able to edit.

Subha avatar Sep 28 '17 18:09 Subha

@JedWatson pushing up this, just noticed that we need the same thing it's opened from February

fzan avatar Nov 16 '17 16:11 fzan

Looks like this ticket is a dupe of #1868 and the suggested solution is to create your own value and option component which handles the rendering and focus/edit etc. behaviour. I haven't tried myself so would be nice if somebody has a codepen/jsfiddle.

jnachtigall avatar Jan 05 '18 13:01 jnachtigall

I've just run into the same issue and haven't been able to find a solution yet. Does anyone know whether there is a workaround? I'd really appreciate any help since I'd need to get this feature working asap. Thanks

julian69 avatar Jan 11 '18 01:01 julian69

I see not only me has the same problem! SOLUTION, please come :P

magdalko avatar Jan 16 '18 11:01 magdalko

I was not able to resolve it. Had to do some workaround, not even close to the react-select.

AlexanderTserkovniy avatar Feb 12 '18 09:02 AlexanderTserkovniy

Has anyone found a solution for this? The library is great but this feature would greatly improve UX.

jmaslin avatar Aug 23 '18 23:08 jmaslin

Just encountered this problem: I was hoping to replace an editable-text control that I had with react-select, so that text can still be edited, just with a list of suggestions. But I can't, because react-select does not allow editing...

jwr avatar Aug 31 '18 22:08 jwr

I was not able to resolve it as well.. anyone came up with a solution??

kimbel avatar Feb 20 '19 11:02 kimbel

Two years later... Another +1. @JedWatson ?

burtek avatar Feb 20 '19 12:02 burtek

Another +1. @JedWatson ? This needs to be added as it is a basic requirement.

chetan-zalake avatar Feb 25 '19 09:02 chetan-zalake

With v2.x you can overwrite the internal components of the Select with the Components Framework to either replace or enhance functionality.

Here is a very basic example of a CreateableSelect with editable custom option: CodeSandbox.

Easy to implement with the help of the documentation and a look into the core code here on github.

If you are looking for editable option in a simple Select component, you should think about using unique identifiers for your options to identify them if you change the label (and maybe values).

Rall3n avatar Feb 25 '19 10:02 Rall3n

Another +1, a little shocked this isn't a core feature. @Rall3n thanks for the info but I'm a little confused by the CodeSandbox.. I want to be able to select an item from the dropdown and then edit it. For example, if I want to select option 'AAAAA', delete the last 'A' and type a 'B' so that the input contains 'AAAAB', I don't have to delete the entire item and start over. I can't seem to make that happen with this example...

jonnydodad avatar Mar 07 '19 21:03 jonnydodad

@jonnydodad Easy (using my example as reference):

Edit onChange to not save the value into either value or createdOption, but into just value:

onChange = (option, action) => {
    // If you want to keep the option in the menu, make a copy of the option as this is a reference to the element in the options array.
    var newOption = Object.assign({}, option);

    this.setState({ value: newOption });
}

Remove the __isNew__ check from SingleValue and always render the input:

SingleValue = ({ children, ...props}) => {
    return (<components.SingleValue {...props}>
      <input
        type="text"
        { ... }
      />
    </components.SingleValue>)
};

Update onEditChange to set state to value instead of createdOption:

onEditChange = (e) => {
    /* ... */
    this.setState({ value: newOption })
}

And for good measure remove the selection of this.state.createdOption from the value prop of CreatableSelect:

<CreatableSelect 
    { ... }
    value={this.state.value}
/>

And et voilà: You can now edit every option you have selected.

Rall3n avatar Mar 08 '19 09:03 Rall3n

@Rall3n wow awesome thank you so much!

jonnydodad avatar Mar 09 '19 18:03 jonnydodad