Skip to content

Commit

Permalink
pass outer-ref to useClickOutside
Browse files Browse the repository at this point in the history
not doing so causes the filter menu to disappear in the case where React removes the clicked item from the dom before `useClickOutside` is called
  • Loading branch information
tantaman committed Dec 19, 2023
1 parent af3256f commit 44c53a8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions client/src/widgets/filter-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const FilterMenu = ({
const [filter, setFilter] = useState<Filter | null>(null);
const [filterDropDownVisible, setFilterDropDownVisible] = useState(false);
const [view] = useViewState();
const bodyRef = useRef(document.body);

const {styles, attributes, update} = usePopper(filterRef, popperRef, {
placement: 'bottom-start',
Expand All @@ -50,12 +51,16 @@ const FilterMenu = ({
setFilterDropDownVisible(!filterDropDownVisible);
};

useClickOutside(ref, () => {
if (filterDropDownVisible) {
setFilter(null);
setFilterDropDownVisible(false);
}
});
useClickOutside(
ref,
() => {
if (filterDropDownVisible) {
setFilter(null);
setFilterDropDownVisible(false);
}
},
bodyRef,
);

const filterBys = [
[SignalStrongIcon, Filter.PRIORITY, 'Priority'],
Expand Down

0 comments on commit 44c53a8

Please sign in to comment.