How to set current value or how to enable edit of the selected tag?
Hi guys,
-
The question is simple how to set current value of the input? Like when I put focus there and see already written text.
-
Or how to enable editing of the existing tag, that I could click and continue typing?
Thanks.
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).
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 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.
@JedWatson I also need this for my application. Any ideas how can we implement it ?
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?
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.
@JedWatson pushing up this, just noticed that we need the same thing it's opened from February
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.
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
I see not only me has the same problem! SOLUTION, please come :P
I was not able to resolve it. Had to do some workaround, not even close to the react-select.
Has anyone found a solution for this? The library is great but this feature would greatly improve UX.
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...
I was not able to resolve it as well.. anyone came up with a solution??
Two years later... Another +1. @JedWatson ?
Another +1. @JedWatson ? This needs to be added as it is a basic requirement.
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).
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 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 wow awesome thank you so much!