diff --git a/CHANGELOG.md b/CHANGELOG.md index 940f07d..a87601d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## Unreleased +* [Improving data-testids for actions](https://github.com/flower-platform/react-timeline-10000/pull/109) ## v2.12.0 diff --git a/src/components/ContextMenu/ContextMenu.tsx b/src/components/ContextMenu/ContextMenu.tsx index 63a9f59..ffe89ab 100644 --- a/src/components/ContextMenu/ContextMenu.tsx +++ b/src/components/ContextMenu/ContextMenu.tsx @@ -93,7 +93,7 @@ export class ContextMenu extends React.Component 0)}> {visibleActions.map((action: IAction) => { - const key = visibleActions.indexOf(action); + const key = (action.key instanceof Function ? action.key({ ...this.props.paramsForAction }) : action.key) || visibleActions.indexOf(action); return (!action.renderInMenu ? - : React.cloneElement(action.renderInMenu({ ...this.props.paramsForAction, closeContextMenu: this.close }), { key: visibleActions.indexOf(action), "data-testid": testids.menuItem + "_" + key }) + : React.cloneElement(action.renderInMenu({ ...this.props.paramsForAction, closeContextMenu: this.close }), { key: key, "data-testid": testids.menuItem + "_" + key }) ); }) } diff --git a/src/components/ContextMenu/IAction.ts b/src/components/ContextMenu/IAction.ts index 07b5d69..55bf434 100644 --- a/src/components/ContextMenu/IAction.ts +++ b/src/components/ContextMenu/IAction.ts @@ -49,6 +49,7 @@ export interface IAction { isDisabled?: (param: IActionParam) => boolean, icon?: SemanticShorthandItem, label?: string | ((param: IActionParam) => string), + key?: string | ((param: IActionParam) => string), /** * Function that will be called when user will click this menu entry. Will receives as parameter the current selected items */