React-select: Text cursor location

Created on 4 May 2015  路  29Comments  路  Source: JedWatson/react-select

It may be nitpicking, but after choosing an item in the dropdown the text cursor blinks in front of the displayed text. Wouldn't it make more sense to move it after the text?

categorquestion issuhas-pr issureviewed

Most helpful comment

Throwing in another 2垄: The main issue here is that the behavior of react-select breaks implicit UX contracts users are bringing with them from standard form elements.

The select box here looks like a text input, with cursor flashing, but then you can't select or delete any of the text that appears to be inside it. You quickly learn that if you start typing it will replace the existing text. But it creates a feeling of being artificially hemmed in.

You're also out of luck if you want to perform a new query by deleting some characters from the end of the existing value. You have to start over.

If #2176 works could someone please merge?

All 29 comments

+1

+1

+1

+1

+1

As a side note, anyone have any suggestions as to a quick and dirty way to get it appearing at the end? @dlong500

+1

  • 1 Hi Folks, anyone have any suggestions/ideas/hack as to quick or long way to get it ?

+1

+1

I haven't had much time to look into this myself. I believe the root of the problem is that the actual value is stored in a span element and not the input control. The input is only used for typing, and once a value is chosen it appears that the input is cleared and the span overlay shows the value (thus leaving a blinking cursor in an empty input control).

Perhaps there is a way to have the input's value set to the selected value instead of being empty? Given the structure of this component I don't see an easy way to hack around it without modifying the actual react-select code.

One other possibility that might at least make it not look so odd is to hide the blinking cursor with styling when the input is not active, but this would obscure the fact that a value could be typed in.

The only true fix is going to be having code updated in react-select. Either having the input control value set to the selected value (probably the easiest option) or changing the whole structure of how the component works so that the input control is the primary value holder.

If you don't allow user to enter values, you don't need to display the contents of the input, so you could use:

.Select-input {
  color: transparent;
}

FYI @jerrytom1986 @burritofanatic @dlong500

@adjohnson916 I think most people using this component (at least the ones in this issue) are certainly wanting people to be able to enter values for the typeahead feature that is a large part of what this component provides, so unfortunately that doesn't really solve the issue.

That being said, I think it would actually need to be the following to hide the cursor (and the text someone might type):

.Select-input > input {
  color: transparent;
}

@dlong500 Agreed, a general solution is needed that works with typeahead. Just thought I'd mention as that fix suited my use case.

@JedWatson any updates would be appreciated. Thanks.

+1

+1

Throwing in another 2垄: The main issue here is that the behavior of react-select breaks implicit UX contracts users are bringing with them from standard form elements.

The select box here looks like a text input, with cursor flashing, but then you can't select or delete any of the text that appears to be inside it. You quickly learn that if you start typing it will replace the existing text. But it creates a feeling of being artificially hemmed in.

You're also out of luck if you want to perform a new query by deleting some characters from the end of the existing value. You have to start over.

If #2176 works could someone please merge?

@glortho I replaced official react-native with that one from PR, added proper typings for TS and I had couple of errors while selecting elements from search. I'm not sure if it works - I don't test it properly.

+1, I agree with @glortho, this breaks the expected convention

+1

The following CSS solved the issue for me -

  .is-focused.has-value.Select--single {
    .Select-control {
      .Select-value {
        position: relative;
        display: inline-block;
      }

      .Select-input {
        display: inline-block;
        vertical-align: top;
        padding-left: 0px;
      }
    }
  }

@dlong500
I just made the text inside gray while menu is open which makes it look a lot better.

image

here is a sample that will get you the result

const styles = {
  singleValue: (base, state) => ({
    ...base,
    color: state.selectProps.menuIsOpen ? '#some-shade-of-gray' : base.color,
  }),
}

... <Select {...otherRequiredProps} styles={styles} />

I'm facing this problem too. My case is actually worse since it is a rich react node with an avatar + text.

The cursor blinks below the avatar and users don't know they can actually search.

Inline search is very tricky. It is not that terrible for text-based select, but for anything else it does not work really.

Is there an easy to way to move the search to be inside the drop contents?

I had a same issue, and I found that Material-UI's demo (https://material-ui.com/demos/autocomplete/) didn't have this issue.
In there, I found out passing in SingleValue component would solve this issue.

Here's a codesandbox example that material-ui's demo uses.
https://codesandbox.io/s/34k6v4vr6

const styles = {
singleValue: (base, state) => ({
...base,
color: state.selectProps.menuIsOpen ? 'transparent' : base.color,
}),
}

...