48003887ce
Closes #5117 TO FIX in another PR: right now, the "Vertical Dots" LightIconButton inside the Dropdown menu sometimes needs to be clicked twice to open the nested dropdown, not sure why 🤔 Maybe an `event.preventDefault()` is needed somewhere? <img width="369" alt="image" src="https://github.com/twentyhq/twenty/assets/3098428/dd0c771a-c18d-4eb2-8ed6-b107f56711e9"> --------- Co-authored-by: Jérémy Magrin <jeremy.magrin@gmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
import { useRecoilState } from 'recoil';
|
|
|
|
import { useDropdownStates } from '@/ui/layout/dropdown/hooks/internal/useDropdownStates';
|
|
import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope';
|
|
import { getScopeIdOrUndefinedFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdOrUndefinedFromComponentId';
|
|
import { isDefined } from '~/utils/isDefined';
|
|
|
|
export const useDropdown = (dropdownId?: string) => {
|
|
const {
|
|
scopeId,
|
|
dropdownHotkeyScopeState,
|
|
dropdownWidthState,
|
|
isDropdownOpenState,
|
|
} = useDropdownStates({
|
|
dropdownScopeId: getScopeIdOrUndefinedFromComponentId(dropdownId),
|
|
});
|
|
|
|
const {
|
|
setHotkeyScopeAndMemorizePreviousScope,
|
|
goBackToPreviousHotkeyScope,
|
|
} = usePreviousHotkeyScope();
|
|
|
|
const [dropdownHotkeyScope] = useRecoilState(dropdownHotkeyScopeState);
|
|
|
|
const [dropdownWidth, setDropdownWidth] = useRecoilState(dropdownWidthState);
|
|
|
|
const [isDropdownOpen, setIsDropdownOpen] =
|
|
useRecoilState(isDropdownOpenState);
|
|
|
|
const closeDropdown = () => {
|
|
goBackToPreviousHotkeyScope();
|
|
setIsDropdownOpen(false);
|
|
};
|
|
|
|
const openDropdown = () => {
|
|
setIsDropdownOpen(true);
|
|
if (isDefined(dropdownHotkeyScope)) {
|
|
setHotkeyScopeAndMemorizePreviousScope(
|
|
dropdownHotkeyScope.scope,
|
|
dropdownHotkeyScope.customScopes,
|
|
);
|
|
}
|
|
};
|
|
|
|
const toggleDropdown = () => {
|
|
if (isDropdownOpen) {
|
|
closeDropdown();
|
|
} else {
|
|
openDropdown();
|
|
}
|
|
};
|
|
|
|
return {
|
|
scopeId,
|
|
isDropdownOpen,
|
|
closeDropdown,
|
|
toggleDropdown,
|
|
openDropdown,
|
|
dropdownWidth,
|
|
setDropdownWidth,
|
|
};
|
|
};
|