Skip to content

Commit

Permalink
Right Click Menu: Fix the click problems (#8895)
Browse files Browse the repository at this point in the history
  • Loading branch information
samwhale authored and swissspidy committed Sep 7, 2021
1 parent a8cb90f commit c81b5d8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
10 changes: 6 additions & 4 deletions packages/design-system/src/components/contextMenu/mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { useEffect, useRef } from '@web-stories-wp/react';
/**
* Internal dependencies
*/
import { noop } from '../../utils';
import { POPOVER_Z_INDEX } from './styled';

const ScreenMask = styled.div`
Expand Down Expand Up @@ -56,14 +55,17 @@ export default function Mask({ onDismiss }) {
return (
<>
{/*
Disable Reason: Allow pointer events to pass through if there's no 'onDismiss' to preserve transition
Disable Reason: Prevent events from propagating so click + drag isn't triggered in the editor.
*/}
{/* eslint-disable-next-line styled-components-a11y/click-events-have-key-events, styled-components-a11y/no-static-element-interactions */}
{/* eslint-disable-next-line styled-components-a11y/no-static-element-interactions */}
<ScreenMask
ref={maskRef}
data-testid="context-menu-mask"
hasOnDismiss={Boolean(onDismiss)}
onClick={onDismiss || noop}
onMouseDown={(evt) => {
evt.stopPropagation();
onDismiss?.();
}}
/>
</>
);
Expand Down
8 changes: 6 additions & 2 deletions packages/design-system/src/components/contextMenu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,18 @@ const Menu = ({
]);

return (
<MenuWrapper ref={wrapperRef} isIconMenu={isIconMenu} role="menu">
<MenuWrapper
ref={wrapperRef}
isIconMenu={isIconMenu}
role="menu"
{...props}
>
<MenuList
data-testid="context-menu-list"
ref={listRef}
isIconMenu={isIconMenu}
aria-label={groupLabel}
role="group"
{...props}
>
{items.map(({ separator, onFocus, ...itemProps }, index) => (
<li
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('ContextMenu', () => {

const mask = screen.getByTestId('context-menu-mask');
act(() => {
fireEvent.click(mask);
fireEvent.mouseDown(mask);
});

expect(onDismiss).toHaveBeenCalledTimes(1);
Expand All @@ -70,7 +70,7 @@ describe('ContextMenu', () => {

const mask = screen.getByTestId('context-menu-mask');
act(() => {
fireEvent.click(mask, { button: 'right' });
fireEvent.mouseDown(mask, { button: 'right' });
});

expect(onDismiss).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const RightClickMenu = () => {
'web-stories'
)}
maskRef={maskRef}
onMouseDown={(evt) => evt.stopPropagation()}
/>
</RightClickMenuContainer>
</DirectionAware>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function SelectionCanvas({ children }) {
};

const onMouseDown = (evt) => {
// Selecting the background element should be handeled at the frameElement level
// Selecting the background element should be handled at the frameElement level
if (!nodesById[currentPage.elements[0].id].contains(evt.target)) {
if (selectedElements.length) {
clearSelection();
Expand Down

0 comments on commit c81b5d8

Please sign in to comment.