Skip to content

Commit

Permalink
fix(fuselage): MenuItem onPointerUp event behavior (#1422)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliajforesti authored Aug 1, 2024
1 parent faa2da5 commit 0df364b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-glasses-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/fuselage": patch
---

fix(fuselage): `MenuItem` onPointerUp event behavior
17 changes: 10 additions & 7 deletions packages/fuselage/src/components/Menu/V2/MenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Node } from '@react-types/shared';
import type { ReactNode } from 'react';
import { useRef } from 'react';
import { useMenuItem } from 'react-aria';
import { mergeProps, useMenuItem } from 'react-aria';
import type { TreeState } from 'react-stately';

import { MenuItemDescription } from '.';
Expand All @@ -18,15 +18,18 @@ type MenuItemProps = {

function MenuItem({ item, state }: MenuItemProps) {
const ref = useRef(null);
const { menuItemProps, isFocused, isDisabled } = useMenuItem(
{ key: item.key },
state,
ref
);
const {
menuItemProps: { onPointerUp, ...menuItemProps },
isFocused,
isDisabled,
} = useMenuItem({ key: item.key }, state, ref);

// There's an issue caused by conflicting event handlers. The popover opens on onPointerDown and the selection event for both, the menu (listbox), happens on onPointerUp.
// As a workaround, we are overwriting `onPointerDown` event with `onPointerUp`

return (
<MenuOption
{...menuItemProps}
{...mergeProps(menuItemProps, { onPointerDown: onPointerUp })}
ref={ref}
focus={isFocused}
disabled={isDisabled}
Expand Down

0 comments on commit 0df364b

Please sign in to comment.