From 96bcef44af8e8f26e40abc7d72d6174cc0b311d4 Mon Sep 17 00:00:00 2001 From: Justin Kambic Date: Tue, 31 Mar 2020 16:58:18 -0400 Subject: [PATCH] Add an onBlur handler for the kuery bar. Only resubmit when input changes. (#61901) (#62030) --- .../components/functional/kuery_bar/typeahead/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/uptime/public/components/functional/kuery_bar/typeahead/index.js b/x-pack/legacy/plugins/uptime/public/components/functional/kuery_bar/typeahead/index.js index 9b8bdb50441c9..0ea5e1e2b8372 100644 --- a/x-pack/legacy/plugins/uptime/public/components/functional/kuery_bar/typeahead/index.js +++ b/x-pack/legacy/plugins/uptime/public/components/functional/kuery_bar/typeahead/index.js @@ -27,6 +27,7 @@ export class Typeahead extends Component { index: null, value: '', inputIsPristine: true, + lastSubmitted: '', }; static getDerivedStateFromProps(props, state) { @@ -151,7 +152,10 @@ export class Typeahead extends Component { }; onSubmit = () => { - this.props.onSubmit(this.state.value); + if (this.state.lastSubmitted !== this.state.value) { + this.props.onSubmit(this.state.value); + this.setState({ lastSubmitted: this.state.value }); + } this.setState({ isSuggestionsVisible: false }); }; @@ -177,6 +181,7 @@ export class Typeahead extends Component { value={this.state.value} onKeyDown={this.onKeyDown} onKeyUp={this.onKeyUp} + onBlur={this.onSubmit} onChange={this.onChangeInputValue} onClick={this.onClickInput} autoComplete="off"