Skip to content

Commit

Permalink
fix(dropdown): call event handler when the state change
Browse files Browse the repository at this point in the history
  • Loading branch information
clementprevot committed Nov 29, 2023
1 parent 217d6ce commit ebea833
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/fractal/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,18 @@ export const Dropdown = forwardRef<CombinedRefs, DropdownProps>(
return
}

const wasOpened = isOpen
setIsOpen(isOpened)

if (isFunction(onMenuOpenChange)) {
if (isFunction(onMenuOpenChange) && wasOpened !== isOpened) {
onMenuOpenChange(isOpened)
}

if (isOpened && isFunction(onOpen)) {
if (!wasOpened && isOpened && isFunction(onOpen)) {
onOpen()
}

if (!isOpened && isFunction(onClose)) {
if (wasOpened && !isOpened && isFunction(onClose)) {
onClose()
}
}
Expand Down

0 comments on commit ebea833

Please sign in to comment.