diff --git a/src/components/Table/__stories__/Table.stories.tsx b/src/components/Table/__stories__/Table.stories.tsx index f4bd01a74..d2024becc 100644 --- a/src/components/Table/__stories__/Table.stories.tsx +++ b/src/components/Table/__stories__/Table.stories.tsx @@ -13,6 +13,7 @@ import { DataItem, } from './utils'; import {TableAction, TableSettingsData} from '..'; +import {action} from '@storybook/addon-actions'; export default { title: 'Components/Table', @@ -79,7 +80,10 @@ const WithTableActionsTemplate: Story> = (args) => { const getRowActions = (item: DataItem, index: number): TableAction[] => [ { text: 'default', - handler: () => alert(JSON.stringify(item)), + handler: (...handlerArgs) => { + alert(JSON.stringify(item)); + action('default')(handlerArgs); + }, }, { text: 'disabled', @@ -89,7 +93,10 @@ const WithTableActionsTemplate: Story> = (args) => { { text: 'danger theme', theme: 'danger', - handler: () => alert(index), + handler: (...handlerArgs) => { + alert(index); + action('danger')(handlerArgs); + }, }, ]; return ; diff --git a/src/components/Table/hoc/withTableActions/withTableActions.tsx b/src/components/Table/hoc/withTableActions/withTableActions.tsx index b837016d1..9a405bffb 100644 --- a/src/components/Table/hoc/withTableActions/withTableActions.tsx +++ b/src/components/Table/hoc/withTableActions/withTableActions.tsx @@ -35,7 +35,11 @@ interface PopupData { export interface TableAction { text: string; - handler: (item: I, index: number) => void; + handler: ( + item: I, + index: number, + event: React.MouseEvent, + ) => void; disabled?: boolean; theme?: MenuItemProps['theme']; } @@ -183,8 +187,12 @@ export function withTableActions( } }; - private handleActionClick = (action: TableAction, data: PopupData) => { - action.handler(data.item, data.index); + private handleActionClick = ( + action: TableAction, + data: PopupData, + event: React.MouseEvent, + ) => { + action.handler(data.item, data.index, event); this.closePopup(); };