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

defaultValue not selecting the value, dropdown box remains open

Open benrlodge opened this issue 9 years ago • 7 comments

When I use defaultValue if there is a fuzzy match, it does not select the matching value, but instead shows the matching options (as if you typed in the value). I may be able to look into submitting a PR if this isn't already being worked on.

benrlodge avatar Dec 14 '15 16:12 benrlodge

actually, i'm seeing the drop-down remain open even if I have a single match. Not sure if this is by design, but I would prefer, or at least have the option, to have the default value pre-selected.

benrlodge avatar Dec 14 '15 17:12 benrlodge

@fmoo not sure if it's the best approach, but I have something working where I check if this.props.defaultValue exists as well as a hasRendered flag (could be a better word for this...) which will be false on first run, then flip it true when the user first starts to interact with the input box again at _onTextEntryUpdated.

   // added:
  _renderIncrementalSearchResults: function() {
     // A default value was passed in
    if (this.props.defaultValue && !this.state.hasRendered) {
      return "";
    }
  _onTextEntryUpdated: function() {
    var value = this.refs.entry.getDOMNode().value;
    this.setState({visible: this.getOptionsForValue(value, this.props.options),
                   selection: null,
                   selectionIndex: 0,
                   hasRendered: true, // <-- added
                   entryValue: value});
  }

benrlodge avatar Dec 17 '15 19:12 benrlodge

+1 for this. @benrlodge is there any way without modifying the source code? :(

ragebiswas avatar Dec 28 '15 13:12 ragebiswas

'fraid not from what I can tell. I'm working off a forked version in the mean time.

benrlodge avatar Dec 28 '15 14:12 benrlodge

~~This could be a separate issue - but related - I'm also realizing it would be helpful to have some kind of currentValue option that can be accessed at componentWillReceiveProps, as I'm trying to implement routing with default values that would be pre-selected based on the routers params.~~

my bad. didnt see props.value

benrlodge avatar Dec 28 '15 18:12 benrlodge

@benrlodge I'm coming to this from #176

What's the use case here? Is this something that Tokenizer defaultSelected doesn't solve? Are you only using Typeahead and not Tokenizer?

nosilleg avatar Apr 02 '16 19:04 nosilleg

i'm only using Typeahead @nosilleg

As fmoo mentioned, it's the same issue noted here https://github.com/fmoo/react-typeahead/issues/21 (i just didn't discover that when posting this issue)

benrlodge avatar Apr 07 '16 16:04 benrlodge