From dd7caab7f18f19d2cabeec462e89d63985ccad5c Mon Sep 17 00:00:00 2001 From: Eric Olkowski Date: Tue, 19 Mar 2024 09:27:50 -0400 Subject: [PATCH 1/2] fix(Table): added ActionsColumn prop to control close on click --- .../src/components/Table/ActionsColumn.tsx | 56 ++++++++++--------- .../src/components/Table/TableTypes.tsx | 2 + 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/packages/react-table/src/components/Table/ActionsColumn.tsx b/packages/react-table/src/components/Table/ActionsColumn.tsx index 5d8f01f0b94..6d194eacd81 100644 --- a/packages/react-table/src/components/Table/ActionsColumn.tsx +++ b/packages/react-table/src/components/Table/ActionsColumn.tsx @@ -116,35 +116,37 @@ const ActionsColumnBase: React.FunctionComponent = ({ {items .filter((item) => !item.isOutsideDropdown) - .map(({ title, itemKey, onClick, tooltipProps, isSeparator, ...props }, index) => { - if (isSeparator) { - return ; - } - const item = ( - { - onActionClick(event, onClick); - onToggle(); - }} - {...props} - key={itemKey || index} - data-key={itemKey || index} - ref={index === 0 ? firstActionItemRef : undefined} - > - {title} - - ); - - if (tooltipProps?.content) { - return ( - - {item} - + .map( + ({ title, itemKey, onClick, tooltipProps, isSeparator, shouldCloseOnClick = true, ...props }, index) => { + if (isSeparator) { + return ; + } + const item = ( + { + onActionClick(event, onClick); + shouldCloseOnClick && onToggle(); + }} + {...props} + key={itemKey || index} + data-key={itemKey || index} + ref={index === 0 ? firstActionItemRef : undefined} + > + {title} + ); - } else { - return item; + + if (tooltipProps?.content) { + return ( + + {item} + + ); + } else { + return item; + } } - })} + )} diff --git a/packages/react-table/src/components/Table/TableTypes.tsx b/packages/react-table/src/components/Table/TableTypes.tsx index e0658d41f3e..9fb53517a36 100644 --- a/packages/react-table/src/components/Table/TableTypes.tsx +++ b/packages/react-table/src/components/Table/TableTypes.tsx @@ -166,6 +166,8 @@ export interface IAction extends Omit, P onClick?: (event: React.MouseEvent, rowIndex: number, rowData: IRowData, extraData: IExtraData) => void; /** Flag indicating this action should be placed outside the actions menu, beside the toggle */ isOutsideDropdown?: boolean; + /** Flag indicating whether the actions dropdown should close after an item is clicked. */ + shouldCloseOnClick?: boolean; } export interface ISeparator extends IAction { From 19d044aeb1818314ee0361846189a7ad1996ba7c Mon Sep 17 00:00:00 2001 From: Eric Olkowski Date: Wed, 20 Mar 2024 16:45:20 -0400 Subject: [PATCH 2/2] Added prop to prevent onOpenChange from being called --- packages/react-table/src/components/Table/ActionsColumn.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/react-table/src/components/Table/ActionsColumn.tsx b/packages/react-table/src/components/Table/ActionsColumn.tsx index 6d194eacd81..697bd42dfba 100644 --- a/packages/react-table/src/components/Table/ActionsColumn.tsx +++ b/packages/react-table/src/components/Table/ActionsColumn.tsx @@ -30,6 +30,8 @@ export interface ActionsColumnProps extends Omit, ' innerRef?: React.Ref; /** Ref to forward to the first item in the popup menu */ firstActionItemRef?: React.Ref; + /** Flag indicating that the dropdown's onOpenChange callback should not be called. */ + isOnOpenChangeDisabled?: boolean; } const ActionsColumnBase: React.FunctionComponent = ({ @@ -44,6 +46,7 @@ const ActionsColumnBase: React.FunctionComponent = ({ }, innerRef, firstActionItemRef, + isOnOpenChangeDisabled = false, ...props }: ActionsColumnProps) => { const [isOpen, setIsOpen] = React.useState(false); @@ -91,7 +94,7 @@ const ActionsColumnBase: React.FunctionComponent = ({ setIsOpen(isOpen)} + onOpenChange={!isOnOpenChangeDisabled ? (isOpen: boolean) => setIsOpen(isOpen) : undefined} toggle={(toggleRef: any) => actionsToggle ? ( actionsToggle({ onToggle, isOpen, isDisabled, toggleRef })