From 4cac26f63472b657b2285604e2e643e6313850b5 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Wed, 15 Mar 2023 14:57:59 +0200 Subject: [PATCH] Align open/close behaviour with react-select --- assets/js/dashboard/components/combobox.js | 17 +++++++---------- assets/js/dashboard/stats/modals/filter.js | 4 ++-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/assets/js/dashboard/components/combobox.js b/assets/js/dashboard/components/combobox.js index 9b2e1ba9c..2c9060143 100644 --- a/assets/js/dashboard/components/combobox.js +++ b/assets/js/dashboard/components/combobox.js @@ -40,21 +40,18 @@ export default function PlausibleCombobox(props) { } function selectOption(option) { - props.onChange([...props.values, option], () => { - setOptions(options.filter(o => o != option)) - searchRef.current.value = '' - searchRef.current.focus() - }) + props.onChange([...props.values, option]) + setOpen(false) + searchRef.current.value = '' + searchRef.current.focus() } function removeOption(option, e) { e.stopPropagation() const newValues = props.values.filter((val) => val.value !== option.value) - props.onChange(newValues, () => { - searchRef.current.focus() - setOpen(true) - fetchOptions(searchRef.current.value) - }) + props.onChange(newValues) + searchRef.current.focus() + setOpen(false) } const handleClick = useCallback((e) => { diff --git a/assets/js/dashboard/stats/modals/filter.js b/assets/js/dashboard/stats/modals/filter.js index e781633f3..78f385cfa 100644 --- a/assets/js/dashboard/stats/modals/filter.js +++ b/assets/js/dashboard/stats/modals/filter.js @@ -108,12 +108,12 @@ class FilterModal extends React.Component { } onChange(filterName) { - return (selection, callback) => { + return (selection) => { this.setState(prevState => ({ formState: Object.assign(prevState.formState, { [filterName]: Object.assign(prevState.formState[filterName], { clauses: selection }) }) - }), callback) + })) } }