Skip to content

Commit

Permalink
fix: Country Dropdown not closing with AddressInput (#8147)
Browse files Browse the repository at this point in the history
## Description

- This PR fixes #8080 
- The Country Selector dropdown closes with Address Input `clickOutside`
function

## Changes


https://github.com/user-attachments/assets/1ab85175-9ce9-40d2-ac52-14bfe87e254f

---------

Co-authored-by: Devessier <[email protected]>
  • Loading branch information
harshit078 and Devessier authored Oct 29, 2024
1 parent 94f2e10 commit 7901dbc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const Dropdown = ({
closeDropdown,
dropdownWidth,
setDropdownPlacement,
resetDropdown,
} = useDropdown(dropdownId);

const offsetMiddlewares = [];
Expand Down Expand Up @@ -130,6 +131,12 @@ export const Dropdown = ({
[closeDropdown],
);

useEffect(() => {
return () => {
resetDropdown();
};
}, [resetDropdown]);

return (
<DropdownScope dropdownScopeId={getScopeIdFromComponentId(dropdownId)}>
<div ref={containerRef} className={className}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRecoilState } from 'recoil';
import { useRecoilCallback, useRecoilState } from 'recoil';

import { useDropdownStates } from '@/ui/layout/dropdown/hooks/internal/useDropdownStates';
import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope';
Expand Down Expand Up @@ -56,6 +56,16 @@ export const useDropdown = (dropdownId?: string) => {
}
};

const resetDropdown = useRecoilCallback(
({ reset }) =>
() => {
reset(dropdownHotkeyScopeState);
reset(dropdownWidthState);
reset(isDropdownOpenState);
},
[dropdownHotkeyScopeState, dropdownWidthState, isDropdownOpenState],
);

return {
scopeId,
isDropdownOpen,
Expand All @@ -66,5 +76,6 @@ export const useDropdown = (dropdownId?: string) => {
setDropdownWidth,
dropdownPlacement,
setDropdownPlacement,
resetDropdown,
};
};

0 comments on commit 7901dbc

Please sign in to comment.