Skip to content

Commit

Permalink
CB-6039 prevent click through menu (#3134)
Browse files Browse the repository at this point in the history
* CB-6039 prevent click through menu

* CB-6039
  • Loading branch information
devnaumov authored Dec 16, 2024
1 parent 522620e commit 92c7cef
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 29 deletions.
6 changes: 1 addition & 5 deletions webapp/packages/core-blocks/src/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useCombinedRef } from '../useCombinedRef.js';
import { useObjectRef } from '../useObjectRef.js';
import { useS } from '../useS.js';
import style from './Menu.module.css';
import { type IMenuPanelProps, MenuPanel } from './MenuPanel.js';
import { MenuPanel } from './MenuPanel.js';
import { type IMenuState, MenuStateContext } from './MenuStateContext.js';
import type { IMouseContextMenu } from './useMouseContextMenu.js';

Expand All @@ -33,7 +33,6 @@ interface IMenuProps extends React.ButtonHTMLAttributes<any> {
rtl?: boolean;
hasBindings?: boolean;
panelAvailable?: boolean;
panelProps?: Partial<IMenuPanelProps>;
getHasBindings?: () => boolean;
onVisibleSwitch?: (visible: boolean) => void;
}
Expand All @@ -56,7 +55,6 @@ export const Menu = observer<IMenuProps, HTMLButtonElement>(
modal,
submenu,
rtl,
panelProps,
className,
...props
},
Expand Down Expand Up @@ -155,7 +153,6 @@ export const Menu = observer<IMenuProps, HTMLButtonElement>(
panelAvailable={panelAvailable}
hasBindings={hasBindings}
getHasBindings={getHasBindings}
{...panelProps}
>
{items}
</MenuPanel>
Expand Down Expand Up @@ -190,7 +187,6 @@ export const Menu = observer<IMenuProps, HTMLButtonElement>(
panelAvailable={panelAvailable}
hasBindings={hasBindings}
getHasBindings={getHasBindings}
{...panelProps}
>
{items}
</MenuPanel>
Expand Down
9 changes: 3 additions & 6 deletions webapp/packages/core-blocks/src/Menu/MenuPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useS } from '../useS.js';
import { MenuEmptyItem } from './MenuEmptyItem.js';
import style from './MenuPanel.module.css';

export interface IMenuPanelProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
export interface IMenuPanelProps {
label: string;
menu: MenuStateReturn; // from reakit useMenuState
panelAvailable?: boolean;
Expand All @@ -26,13 +26,11 @@ export interface IMenuPanelProps extends Omit<React.HTMLAttributes<HTMLDivElemen
children: React.ReactNode | (() => React.ReactNode);
rtl?: boolean;
submenu?: boolean;
className?: string;
}

export const MenuPanel = observer<IMenuPanelProps, HTMLDivElement>(
forwardRef(function MenuPanel(
{ label, menu, submenu, panelAvailable = true, rtl, getHasBindings, hasBindings, children, className, ...rest },
ref,
) {
forwardRef(function MenuPanel({ label, menu, submenu, panelAvailable = true, rtl, getHasBindings, hasBindings, children, className }, ref) {
const translate = useTranslate();
const styles = useS(style);
const visible = menu.visible;
Expand All @@ -57,7 +55,6 @@ export const MenuPanel = observer<IMenuPanelProps, HTMLDivElement>(
{...menu}
aria-label={translate(label)}
visible={panelAvailable}
{...rest}
>
<div dir={rtl ? 'rtl' : undefined} data-s-has-bindings={hasBindings} className={s(styles, { menuBox: true })}>
{Children.count(renderedChildren) === 0 && <MenuEmptyItem />}
Expand Down
3 changes: 1 addition & 2 deletions webapp/packages/core-ui/src/ContextMenu/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { MenuItemRenderer } from './MenuItemRenderer.js';
// TODO the click doesn't work for React components as children
export const ContextMenu = observer<IContextMenuProps, HTMLButtonElement>(
forwardRef(function ContextMenu(
{ mouseContextMenu, menu: menuData, disclosure, children, placement, visible, onVisibleSwitch, modal, rtl, panelProps, ...props },
{ mouseContextMenu, menu: menuData, disclosure, children, placement, visible, onVisibleSwitch, modal, rtl, ...props },
ref,
) {
const translate = useTranslate();
Expand Down Expand Up @@ -82,7 +82,6 @@ export const ContextMenu = observer<IContextMenuProps, HTMLButtonElement>(
placement={placement}
disabled={disabled}
disclosure={disclosure}
panelProps={panelProps}
getHasBindings={handlers.hasBindings}
onVisibleSwitch={handlers.handleVisibleSwitch}
>
Expand Down
3 changes: 1 addition & 2 deletions webapp/packages/core-ui/src/ContextMenu/IContextMenuProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { ButtonHTMLAttributes } from 'react';
import type { MenuInitialState } from 'reakit';

import type { IMenuPanelProps, IMouseContextMenu } from '@cloudbeaver/core-blocks';
import type { IMouseContextMenu } from '@cloudbeaver/core-blocks';
import type { IMenuData } from '@cloudbeaver/core-view';

export interface IContextMenuBaseProps extends React.PropsWithChildren {
Expand All @@ -26,7 +26,6 @@ export interface IContextMenuProps extends Omit<ButtonHTMLAttributes<any>, 'chil
modal?: boolean;
visible?: boolean;
rtl?: boolean;
panelProps?: Partial<IMenuPanelProps>;
children?: React.ReactNode | ContextMenuRenderingChildren;
onVisibleSwitch?: (visible: boolean) => void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* you may not use this file except in compliance with the License.
*/

.container {
display: flex;
}

.contextMenu {
padding: 0;
height: 16px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,21 @@ export const CellMenu = observer<Props>(function CellMenu({ model, actions, spre

return (
<SContext registry={registry}>
<ContextMenu
className={s(style, { contextMenu: true })}
menu={menu}
placement="auto-end"
panelProps={{ onMouseUp: markStopPropagation, onDoubleClick: stopPropagation }}
tabIndex={-1}
modal
disclosure
onVisibleSwitch={onStateSwitch}
>
<div role="button" className={s(style, { trigger: true })} onMouseUp={markStopPropagation} onDoubleClick={stopPropagation}>
<Icon className={s(style, { icon: true })} name="snack" viewBox="0 0 16 10" />
</div>
</ContextMenu>
<div className={s(style, { container: true })} onMouseUp={markStopPropagation} onDoubleClick={stopPropagation}>
<ContextMenu
className={s(style, { contextMenu: true })}
menu={menu}
placement="auto-end"
tabIndex={-1}
modal
disclosure
onVisibleSwitch={onStateSwitch}
>
<div role="button" className={s(style, { trigger: true })}>
<Icon className={s(style, { icon: true })} name="snack" viewBox="0 0 16 10" />
</div>
</ContextMenu>
</div>
</SContext>
);
});

0 comments on commit 92c7cef

Please sign in to comment.