Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Revert earlier attempt to auto-close menus when they lose focus
Browse files Browse the repository at this point in the history
gnapse committed Mar 11, 2024
1 parent 130ccf4 commit 0b7ae84
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/menu/menu.tsx
Original file line number Diff line number Diff line change
@@ -161,12 +161,6 @@ const MenuList = polymorphicComponent<'div', MenuListProps>(function MenuList(
className={classNames('reactist_menulist', exceptionallySetClassName)}
getAnchorRect={getAnchorRect ?? undefined}
modal={modal}
onBlur={(event) => {
if (!event.relatedTarget) return
if (event.currentTarget.contains(event.relatedTarget)) return
if (event.relatedTarget?.closest('[role^="menu"]')) return
menuStore.hide()
}}
/>
</Portal>
) : null
@@ -183,17 +177,20 @@ type MenuItemProps = {
* `onSelect` callbacks to each menu item.
*/
value?: string

/**
* The content inside the menu item.
*/
children: React.ReactNode

/**
* When `true` the menu item is disabled and won't be selectable or be part of the keyboard
* navigation across the menu options.
*
* @default true
*/
disabled?: boolean

/**
* When `true` the menu will close when the menu item is selected, in addition to performing the
* action that the menu item is set out to do.
@@ -204,6 +201,7 @@ type MenuItemProps = {
* @default true
*/
hideOnSelect?: boolean

/**
* The action to perform when the menu item is selected.
*
@@ -212,6 +210,7 @@ type MenuItemProps = {
* achieve the same effect conditionally and dynamically deciding at run time.
*/
onSelect?: () => unknown

/**
* The event handler called when the menu item is clicked.
*
@@ -310,7 +309,7 @@ const SubMenu = React.forwardRef<HTMLDivElement, SubMenuProps>(function SubMenu(

const handleSubItemSelect = React.useCallback(
function handleSubItemSelect(value: string | null | undefined) {
if (onItemSelect) onItemSelect(value)
onItemSelect?.(value)
parentMenuItemSelect?.(value)
parentMenuHide()
},
@@ -319,8 +318,7 @@ const SubMenu = React.forwardRef<HTMLDivElement, SubMenuProps>(function SubMenu(

const [button, list] = React.Children.toArray(children)

// Ariakit needs to be able to pass props to the MenuButton
// and combine it with the MenuItem component
// Ariakit needs to be able to pass props to the MenuButton and combine it with the MenuItem component
const renderMenuButton = React.useCallback(
function renderMenuButton(props: MenuButtonProps) {
return React.cloneElement(button as React.ReactElement, props)

0 comments on commit 0b7ae84

Please sign in to comment.