Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dropdown): respect closeOnSelect prop on DropdownItem(#2290) #2598

Open
wants to merge 9 commits into
base: canary
Choose a base branch
from
5 changes: 5 additions & 0 deletions .changeset/warm-planets-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/menu": patch
---

fix(dropdown): respect closeOnSelect prop on DropdownItem(#2290)
gtoxlili marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 8 additions & 2 deletions packages/components/menu/src/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {forwardRef} from "@nextui-org/system";
import {ForwardedRef, ReactElement, Ref} from "react";
import {ForwardedRef, Key, ReactElement, Ref} from "react";

import {UseMenuProps, useMenu} from "./use-menu";
import MenuSection from "./menu-section";
Expand All @@ -18,7 +18,7 @@ function Menu<T extends object>(props: Props<T>, ref: ForwardedRef<HTMLUListElem
hideEmptyContent,
variant,
onClose,
onAction,
onAction: onTopAction,
topContent,
bottomContent,
itemClasses,
Expand All @@ -27,6 +27,12 @@ function Menu<T extends object>(props: Props<T>, ref: ForwardedRef<HTMLUListElem
getEmptyContentProps,
} = useMenu<T>({...props, ref});

const onAction = (key: Key) => {
if (closeOnSelect) {
onTopAction?.(key);
}
};

const content = (
<Component {...getListProps()}>
{!state.collection.size && !hideEmptyContent && (
Expand Down