Skip to content

Commit

Permalink
fix some minor issues with onOpenChange events with useDisclosure
Browse files Browse the repository at this point in the history
  • Loading branch information
Southclaws committed Jan 1, 2024
1 parent 34cd940 commit 489b882
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions web/src/utils/useDisclosure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ export function useDisclosure(props: UseDisclosureProps = {}) {
onClose: onCloseProp,
onOpen: onOpenProp,
isOpen: isOpenProp,
onOpenChange: onOpenChangeProp,
id: idProp,
} = props;

const handleOpen = useCallbackRef(onOpenProp);
const handleClose = useCallbackRef(onCloseProp);
const handleOpenChange = useCallbackRef(onOpenChangeProp);

const [isOpenState, setIsOpen] = useState(props.defaultIsOpen || false);

Expand Down Expand Up @@ -76,12 +78,13 @@ export function useDisclosure(props: UseDisclosureProps = {}) {
const onOpenChange = useCallback(
(event: OpenChangeEvent) => {
if (event.open) {
onClose();
} else {
onOpen();
} else {
onClose();
}
handleOpenChange?.(event);
},
[onOpen, onClose],
[onOpen, onClose, handleOpenChange],
);

function getButtonProps(props: HTMLProps = {}): HTMLProps {
Expand Down

2 comments on commit 489b882

@vercel
Copy link

@vercel vercel bot commented on 489b882 Jan 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 489b882 Jan 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.