Skip to content

Commit

Permalink
fix(dcellar-web-ui): custom time modal cannot close while click outside
Browse files Browse the repository at this point in the history
  • Loading branch information
devinxl committed Oct 10, 2023
1 parent 698f35c commit 80ba8b6
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
PopoverFooter,
PopoverHeader,
PopoverTrigger,
useOutsideClick,
} from '@totejs/uikit';
import React, { useCallback, useEffect } from 'react';
import React, { useCallback, useEffect, useRef } from 'react';
import { NumInput } from './NumInput';
import { SizeMenu } from './SizeMenu';
import { DCButton } from '@/components/common/DCButton';
Expand Down Expand Up @@ -39,6 +40,7 @@ export const CustomTime = ({
onChangeInput,
gaClickName,
}: Props) => {
const ref = useRef(null);
const swapTimeUnits = swapObj(TimeUnits);
const handleNavigation = useCallback(
(e: any) => {
Expand All @@ -53,9 +55,13 @@ export const CustomTime = ({
window.removeEventListener('scroll', handleNavigation);
};
}, [handleNavigation]);
useOutsideClick({
ref,
handler: () => isOpen && onClose(),
});

return (
<Popover isOpen={isOpen} placement="bottom">
<Popover isOpen={isOpen} placement="bottom" >
<PopoverTrigger>
<DCButton
variant="ghost"
Expand All @@ -79,6 +85,7 @@ export const CustomTime = ({
</DCButton>
</PopoverTrigger>
<PopoverContent
ref={ref}
w={226}
p={16}
borderRadius={4}
Expand Down

0 comments on commit 80ba8b6

Please sign in to comment.