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

How to keep value in textbox search after choosing it

Open cnits opened this issue 9 years ago • 28 comments

I saw option onBlurResetsInput to set whether to clear input on blur or not.

And I also want to do that after choosing a value. Please show me how to do?

Thanks in advance!

cnits avatar Jun 26 '17 09:06 cnits

Hey @cnits,

just had this issue myself. You'll have to save the selected value somewhere (preferably in your state) and then pass it as value element to the Select on the next render.

Kind Regards, Florian

DigitalFlow avatar Jul 23 '17 10:07 DigitalFlow

This would be useful – sometimes with a searchable Select the user may want to place the cursor in the currently selected value to alter it, or select part of the text to change/remove it.

The display value is misleading because it appears as though you can do this ^, but in fact you cannot. It might be worthwhile to add a keepInputValue.

Another way to potentially go about this would be to provide a custom renderer for the input itself.

Either way you'd want to use the input as the display for the selected value instead of the ValueRenderer. Although, there might be a clever way to approach this that supports both the ValueRenderer prop as well as keeping the selected value in the input.

mshwery avatar Aug 06 '17 04:08 mshwery

any update on this?

jeremymarc avatar Oct 19 '17 00:10 jeremymarc

#2075

jeremymarc avatar Oct 19 '17 15:10 jeremymarc

@cnits @jeremymarc See my comment on #2075

We already have backspaceRemoves that when explicitly set to false should satisfy your use case, right?

oneill-c avatar Oct 20 '17 20:10 oneill-c

@mshwery

This would be useful – sometimes with a searchable Select the user may want to place the cursor in the currently selected value to alter it, or select part of the text to change/remove it.

I think the ability to re-edit the input after selecting a value would be an excellent enhancement to the project. I will put up a PR to this effect if you don't mind.

oneill-c avatar Oct 20 '17 20:10 oneill-c

@mcpolandc @gwyneplaine I don't think "backspaceRemoves" is what we are talking about ; I would like when clicking in the search field to select the current value so you can delete it by typing any key, something like that:

Input field without focus https://www.dropbox.com/s/6u5nl8cfu02ay41/Screenshot%202017-12-07%2013.12.44.png?dl=0

Input field with focus: https://www.dropbox.com/s/k3ic6h4slxe41cl/Screenshot%202017-12-07%2013.13.05.png?dl=0

That was the purpose of my PR #2075

jeremymarc avatar Dec 07 '17 12:12 jeremymarc

anything changed to this issue? It would be awesome to have options to edit the selected text to make new search (doesnt have to write from scratch the names to search)

magdalko avatar Jan 16 '18 10:01 magdalko

I've been having a similar issue to @jeremymarc - here's an example app: https://codesandbox.io/s/q27lnon96

And here's the behaviour:

feb-06-2018 10-44-11

(The GIF isn't showing mouse clicks for some reason, apologies!)

Whether backspaceRemoves is set to false or true, the value still vanishes when Select loses focus (Although it's clearly still preserved in the state of the component, as it re-appears when Select gets focus back).

hollandmatt avatar Feb 06 '18 18:02 hollandmatt

Also running into this issue - the behavior right now creates some usability issues. backspaceRemoves doesn't really address the problem.

Some use cases:

  1. User clicks into text field that has a value already set and sees a blinking cursor, indicating it's an editable text field. Then the user presses the backspace key.
    • Expected behavior: the last character of the string should be deleted (normal behavior with a blinking caret)
    • Actual behavior: the entire string is deleted (if backspaceRemoves is set to true), or nothing happens (if backspaceRemoves is set to false). Both of these behaviors are unexpected.
  2. The user clicks into the text field, sees a blinking cursor, and presses the left arrow key.
    • Expected behavior: the blinking caret should shift one character to the left
    • Actual behavior: no response
  3. The user clicks into text field, sees the blinking caret at the end of the line, and then tries to click in the middle of the string to change the caret location.
    • Expected behavior: the blinking caret changes to the middle of the string, where the user clicked.
    • Actual behavior: no response

Related issues (possibly duplicates): https://github.com/JedWatson/react-select/issues/164#issuecomment-366284492, #250, #2054, #2296

davidcalhoun avatar Apr 04 '18 19:04 davidcalhoun

I am also in need of this feature. The blinking cursor is causing an illusion of a text input interaction, degrading the usability of this component. The intent for my use case is to emulate the behavior of a text input with autocomplete.

DaveOdden avatar Apr 24 '18 13:04 DaveOdden

@DaveOdden (and others) For V2- I was able to enable editable text by setting the inputValue prop on the Select to be whatever text I wanted to show in the input, which works, except for when I select a value in the dropdown, which appears to clear the input, but in actuality sets the opacity to 0. For that, I had to set opacity: 1 !important; in my own CSS for .myContainer input. It took days to figure this out but the input now behaves much better as you can click on the text, highlight it, the cursor appears at the end of the input like a normal text field.

The other thing I had to do was to make sure not to set blank text on the input when the input is focused- the current behavior just clears the input when you click on it, because there is a menu-close action happening which unintentionally sets a blank string on the input. For that, in my onInputChange handler, I do not set my local react state value when !value && action === 'menu-close, and simply return out of the callback so my component is not setting the inputValue to be an empty String.

lusa avatar Jul 18 '18 17:07 lusa

Any update here?

speedo-sp7 avatar Jul 30 '18 09:07 speedo-sp7

When I select a value in the dropdown, which appears to clear the input, but in actuality sets the opacity to 0. For that, I had to set opacity: 1 !important; in my own CSS for .myContainer input.

I ran into this, too. Wondering why this is, and what the intended way of turning it off is.

huttj-liveperson avatar Aug 09 '18 15:08 huttj-liveperson

I believe it's a bug, not a question, so please remove question tag and add bug tag to this issue!

dehghani-mehdi avatar Sep 21 '18 09:09 dehghani-mehdi

+1 for keeping the input value on focus loss

m-apsolon avatar Sep 28 '18 09:09 m-apsolon

+1

mathiouchio avatar Dec 06 '18 20:12 mathiouchio

I fixed it by this way

1- onInputChange:

handleSearch = (value, {action}) => {
if (action === 'menu-close' || action === 'input-blur' || action === 'set-value') {return} 
else { this.setState({searchValue: value})}
};

2- onChange: (so it sets the value of your input same as you selected)

handleSelect = ({label, value, ...rest}) => {
this.setState({ searchValue: e.value })
}

and as @lusa mentioned we need to set opacity: 1 !important of the input field. set inputId on