Skip to content

Commit

Permalink
Select: allow external component close the popover
Browse files Browse the repository at this point in the history
  • Loading branch information
Tai-DucTran committed Sep 19, 2024
1 parent b64b0ed commit c09ecac
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/@next/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface SelectProps {
border?: string;
borderRadius?: string;
required?: boolean;
isPopoverActive?: boolean;
isPlaceholderFloating?: boolean;
}

Expand Down Expand Up @@ -99,6 +100,7 @@ export const Select = ({
borderRadius,
required,
isPlaceholderFloating,
isPopoverActive,
}: SelectProps) => {
const [popoverActive, setPopoverActive] = useState(false);
const [optionListHeight, setOptionListHeight] = useState('');
Expand Down Expand Up @@ -126,6 +128,12 @@ export const Select = ({
setMenuOptions(newState);
};

useEffect(() => {
if (isPopoverActive === false && popoverActive) {
setPopoverActive(false);
}
}, [isPopoverActive, popoverActive]);

const handleClose = () => {
setPopoverActive(false);
onClose?.();
Expand Down

0 comments on commit c09ecac

Please sign in to comment.