From d3bbba6fd0e7f8828d5288d8264367b9df860af9 Mon Sep 17 00:00:00 2001 From: matttdawson <89495499+matttdawson@users.noreply.github.com> Date: Thu, 26 Oct 2023 15:39:28 +1300 Subject: [PATCH] feat: Support submenu in popup menu (#442) --- .../gridForm/GridFormPopoverMenu.tsx | 30 +++++++++++++------ src/stories/grid/GridReadOnly.stories.tsx | 5 ++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/components/gridForm/GridFormPopoverMenu.tsx b/src/components/gridForm/GridFormPopoverMenu.tsx index 4d9c0724..28412fb3 100644 --- a/src/components/gridForm/GridFormPopoverMenu.tsx +++ b/src/components/gridForm/GridFormPopoverMenu.tsx @@ -3,7 +3,7 @@ import { Fragment, ReactElement, useCallback, useEffect, useRef, useState } from import { useGridPopoverContext } from "../../contexts/GridPopoverContext"; import { GridSubComponentContext } from "../../contexts/GridSubComponentContext"; -import { FocusableItem, MenuDivider, MenuItem } from "../../react-menu3"; +import { FocusableItem, MenuDivider, MenuItem, SubMenu } from "../../react-menu3"; import { ClickEvent } from "../../react-menu3/types"; import { ComponentLoadingWrapper } from "../ComponentLoadingWrapper"; import { GridBaseRow } from "../Grid"; @@ -29,6 +29,7 @@ export interface SelectedMenuOptionResult extends M export interface MenuOption { label: ReactElement | string | MenuSeparatorType; + subMenu?: () => ReactElement; action?: (props: { selectedRows: RowType[]; menuOption: SelectedMenuOptionResult }) => Promise; disabled?: string | boolean; hidden?: boolean; @@ -135,14 +136,25 @@ export const GridFormPopoverMenu = (props: GridForm ) : ( !item.hidden && ( - onMenuItemClick(e, item)} - disabled={!!item.disabled} - title={item.disabled && typeof item.disabled !== "boolean" ? item.disabled : ""} - > - {item.label as ReactElement | string} - + {item.subMenu ? ( + + + + ) : ( + onMenuItemClick(e, item)} + disabled={!!item.disabled} + title={item.disabled && typeof item.disabled !== "boolean" ? item.disabled : ""} + > + {item.label as ReactElement | string} + + )} {item.subComponent && subComponentSelected === item && ( {() => ( diff --git a/src/stories/grid/GridReadOnly.stories.tsx b/src/stories/grid/GridReadOnly.stories.tsx index 50010ce6..c5d9af0c 100644 --- a/src/stories/grid/GridReadOnly.stories.tsx +++ b/src/stories/grid/GridReadOnly.stories.tsx @@ -23,6 +23,7 @@ import { GridProps, GridUpdatingContextProvider, GridWrapper, + MenuItem, useGridFilter, wait, } from "../.."; @@ -171,6 +172,10 @@ const GridReadOnlyTemplate: StoryFn = (props: GridProps) => { await wait(1500); }, }, + { + label: "Sub menu...", + subMenu: () => Find..., + }, { label: "Disabled item", disabled: "Disabled for test",