Files
twenty/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useCloseDropdownFromOutside.ts
Lucas Bordeau f8f11894e8 Introduce generic way to close any open dropdown on page location change (#11504)
In this PR we introduce a generic way to close any open dropdown
idempotently, with the hook useCloseAnyOpenDropdown.

We also introduce a generic hook useExecuteTasksOnAnyLocationChange that
is called each time the page location changes.

This way we can close any open dropdown when the page location changes,
which fixes the original issue of having advanced filter dropdown
staying open between page changes.

Fixes https://github.com/twentyhq/core-team-issues/issues/659
2025-04-10 16:00:50 +02:00

15 lines
444 B
TypeScript

import { isDropdownOpenComponentState } from '@/ui/layout/dropdown/states/isDropdownOpenComponentState';
import { useRecoilCallback } from 'recoil';
export const useCloseDropdownFromOutside = () => {
const closeDropdownFromOutside = useRecoilCallback(
({ set }) =>
(dropdownId: string) => {
set(isDropdownOpenComponentState({ scopeId: dropdownId }), false);
},
[],
);
return { closeDropdownFromOutside };
};