Skip to content

Commit 5534679

Browse files
authored
fix: More fixes related to the Ariakit upgrade (#818)
* fix: Reset anchor rect after context menu is closed * fix: Revert earlier attempt to auto-close menus when they lose focus * Prepare new release
1 parent c95df9a commit 5534679

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
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.
44

5+
# v24.1.2-beta
6+
7+
- [Fix] Reset anchor rect after context menu is closed.
8+
- [Fix] Revert earlier attempt to auto-close menus when they lose focus.
9+
510
# v24.1.1-beta
611

712
- [Fix] It was possible to leave a tooltip in a state in which it remained visible all the time. This release fixes the issue.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"email": "henning@doist.com",
77
"url": "http://doist.com"
88
},
9-
"version": "24.1.1-beta",
9+
"version": "24.1.2-beta",
1010
"license": "MIT",
1111
"homepage": "https://github.com/Doist/reactist#readme",
1212
"repository": {

src/menu/menu.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ const ContextMenuTrigger = polymorphicComponent<'div', unknown>(function Context
126126
[setAnchorRect, menuStore],
127127
)
128128

129+
const isOpen = menuStore.useState('open')
130+
React.useEffect(() => {
131+
if (!isOpen) setAnchorRect(null)
132+
}, [isOpen, setAnchorRect])
133+
129134
return React.createElement(component, { ...props, onContextMenu: handleContextMenu, ref })
130135
})
131136

@@ -156,12 +161,6 @@ const MenuList = polymorphicComponent<'div', MenuListProps>(function MenuList(
156161
className={classNames('reactist_menulist', exceptionallySetClassName)}
157162
getAnchorRect={getAnchorRect ?? undefined}
158163
modal={modal}
159-
onBlur={(event) => {
160-
if (!event.relatedTarget) return
161-
if (event.currentTarget.contains(event.relatedTarget)) return
162-
if (event.relatedTarget?.closest('[role^="menu"]')) return
163-
menuStore.hide()
164-
}}
165164
/>
166165
</Portal>
167166
) : null
@@ -178,17 +177,20 @@ type MenuItemProps = {
178177
* `onSelect` callbacks to each menu item.
179178
*/
180179
value?: string
180+
181181
/**
182182
* The content inside the menu item.
183183
*/
184184
children: React.ReactNode
185+
185186
/**
186187
* When `true` the menu item is disabled and won't be selectable or be part of the keyboard
187188
* navigation across the menu options.
188189
*
189190
* @default true
190191
*/
191192
disabled?: boolean
193+
192194
/**
193195
* When `true` the menu will close when the menu item is selected, in addition to performing the
194196
* action that the menu item is set out to do.
@@ -199,6 +201,7 @@ type MenuItemProps = {
199201
* @default true
200202
*/
201203
hideOnSelect?: boolean
204+
202205
/**
203206
* The action to perform when the menu item is selected.
204207
*
@@ -207,6 +210,7 @@ type MenuItemProps = {
207210
* achieve the same effect conditionally and dynamically deciding at run time.
208211
*/
209212
onSelect?: () => unknown
213+
210214
/**
211215
* The event handler called when the menu item is clicked.
212216
*
@@ -305,7 +309,7 @@ const SubMenu = React.forwardRef<HTMLDivElement, SubMenuProps>(function SubMenu(
305309

306310
const handleSubItemSelect = React.useCallback(
307311
function handleSubItemSelect(value: string | null | undefined) {
308-
if (onItemSelect) onItemSelect(value)
312+
onItemSelect?.(value)
309313
parentMenuItemSelect?.(value)
310314
parentMenuHide()
311315
},
@@ -314,8 +318,7 @@ const SubMenu = React.forwardRef<HTMLDivElement, SubMenuProps>(function SubMenu(
314318

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

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

0 commit comments

Comments
 (0)