From 89cc88548e1f73e739be3d300411faa40eac78c0 Mon Sep 17 00:00:00 2001 From: Johannes Baiter <johannes.baiter@bsb-muenchen.de> Date: Thu, 26 Nov 2020 13:55:24 +0100 Subject: [PATCH] Fix undesired resets of content search query Previously, this would happen anytime the input was blurred (fixed by setting the `freeSolo` prop) and for some reason after a re-render, triggered by the `useAutocomplete` hook in MUI (fixed by ignoring updates with an empty value and a 'reset' reason). --- src/components/SearchPanelControls.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/SearchPanelControls.js b/src/components/SearchPanelControls.js index 571c4d2e8..2b8a8887b 100644 --- a/src/components/SearchPanelControls.js +++ b/src/components/SearchPanelControls.js @@ -41,6 +41,11 @@ export class SearchPanelControls extends Component { /** */ handleChange(event, value, reason) { + // For some reason the value gets reset to an empty value from the + // useAutocomplete hook sometimes, we just ignore these cases + if (reason === 'reset' && !value) { + return; + } this.setState({ search: value, suggestions: [], @@ -121,6 +126,7 @@ export class SearchPanelControls extends Component { noOptionsText="" onChange={this.selectItem} onInputChange={this.handleChange} + freeSolo={true} renderInput={params => ( <TextField {...params} -- GitLab