Skip to content

Commit

Permalink
fix: More fixes related to the Ariakit upgrade (#818)
Browse files Browse the repository at this point in the history
* fix: Reset anchor rect after context menu is closed
* fix: Revert earlier attempt to auto-close menus when they lose focus
* Prepare new release
  • Loading branch information
gnapse authored Mar 11, 2024
1 parent c95df9a commit 5534679
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Reactist follows [semantic versioning](https://semver.org/) and doesn't introduce breaking changes (API-wise) in minor or patch releases. However, the appearance of a component might change in a minor or patch release so keep an eye on redesigns and make sure your app still looks and feels like you expect it.

# v24.1.2-beta

- [Fix] Reset anchor rect after context menu is closed.
- [Fix] Revert earlier attempt to auto-close menus when they lose focus.

# v24.1.1-beta

- [Fix] It was possible to leave a tooltip in a state in which it remained visible all the time. This release fixes the issue.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"email": "[email protected]",
"url": "http://doist.com"
},
"version": "24.1.1-beta",
"version": "24.1.2-beta",
"license": "MIT",
"homepage": "https://github.com/Doist/reactist#readme",
"repository": {
Expand Down
21 changes: 12 additions & 9 deletions src/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ const ContextMenuTrigger = polymorphicComponent<'div', unknown>(function Context
[setAnchorRect, menuStore],
)

const isOpen = menuStore.useState('open')
React.useEffect(() => {
if (!isOpen) setAnchorRect(null)
}, [isOpen, setAnchorRect])

return React.createElement(component, { ...props, onContextMenu: handleContextMenu, ref })
})

Expand Down Expand Up @@ -156,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
Expand All @@ -178,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.
Expand All @@ -199,6 +201,7 @@ type MenuItemProps = {
* @default true
*/
hideOnSelect?: boolean

/**
* The action to perform when the menu item is selected.
*
Expand All @@ -207,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.
*
Expand Down Expand Up @@ -305,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()
},
Expand All @@ -314,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)
Expand Down

0 comments on commit 5534679

Please sign in to comment.