From b7fb5b2b7e04d851e1937fad7d25a51243f02343 Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Sun, 22 Jan 2017 22:57:58 -0800 Subject: [PATCH] Textarea: fix clicking on name suggestions This was broken in 4afc1386, which added an onBlur to hide the suggestions when the textarea loses focus. Unfortunately, this fired even when the textarea lost focus to its own suggestions box, and that meant that onSuggestionClick is never called. Setting a short window in which onSuggestionClick can still happen before hiding the suggestion area ensures that clicking still works, while still hiding the suggestions if the user clicks on something else. --- .../components/components/autosuggest_textarea.jsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/components/components/autosuggest_textarea.jsx b/app/assets/javascripts/components/components/autosuggest_textarea.jsx index 57352be902..81ec7a236d 100644 --- a/app/assets/javascripts/components/components/autosuggest_textarea.jsx +++ b/app/assets/javascripts/components/components/autosuggest_textarea.jsx @@ -118,12 +118,19 @@ const AutosuggestTextarea = React.createClass({ }, onBlur () { - this.setState({ suggestionsHidden: true }); + // If we hide the suggestions immediately, then this will prevent the + // onClick for the suggestions themselves from firing. + // Setting a short window for that to take place before hiding the + // suggestions ensures that can't happen. + setTimeout(() => { + this.setState({ suggestionsHidden: true }); + }, 100); }, onSuggestionClick (suggestion, e) { e.preventDefault(); this.props.onSuggestionSelected(this.state.tokenStart, this.state.lastToken, suggestion); + this.textarea.focus(); }, componentWillReceiveProps (nextProps) {