diff --git a/packages/compass-components/src/components/actions/dropdown-menu-button.tsx b/packages/compass-components/src/components/actions/dropdown-menu-button.tsx index 9ededfb98ff..02ef220b739 100644 --- a/packages/compass-components/src/components/actions/dropdown-menu-button.tsx +++ b/packages/compass-components/src/components/actions/dropdown-menu-button.tsx @@ -48,7 +48,7 @@ export function DropdownMenuButton({ const menuTriggerRef = useRef(null); const [isMenuOpen, setIsMenuOpen] = useState(false); - const onClick = useCallback( + const onClick: React.MouseEventHandler = useCallback( (evt) => { evt.stopPropagation(); if (evt.currentTarget.dataset.menuitem) { @@ -56,7 +56,11 @@ export function DropdownMenuButton({ // Workaround for https://jira.mongodb.org/browse/PD-1674 menuTriggerRef.current?.focus(); } - onAction(evt.currentTarget.dataset.action); + const actionName = evt.currentTarget.dataset.action; + if (typeof actionName !== 'string') { + throw new Error('Expected element to have a "data-action" attribute'); + } + onAction(actionName as Action); }, [onAction] ); diff --git a/packages/compass-components/src/components/actions/item-action-group.tsx b/packages/compass-components/src/components/actions/item-action-group.tsx index d4ed94a4b55..869edb25f2b 100644 --- a/packages/compass-components/src/components/actions/item-action-group.tsx +++ b/packages/compass-components/src/components/actions/item-action-group.tsx @@ -43,10 +43,14 @@ export function ItemActionGroup({ isVisible = true, 'data-testid': dataTestId, }: ItemActionGroupProps) { - const onClick = useCallback( + const onClick: React.MouseEventHandler = useCallback( (evt) => { evt.stopPropagation(); - onAction(evt.currentTarget.dataset.action); + const actionName = evt.currentTarget.dataset.action; + if (typeof actionName !== 'string') { + throw new Error('Expected element to have a "data-action" attribute'); + } + onAction(actionName as Action); }, [onAction] ); diff --git a/packages/compass-components/src/components/actions/item-action-menu.tsx b/packages/compass-components/src/components/actions/item-action-menu.tsx index 6205862312c..c0b2ac9bf47 100644 --- a/packages/compass-components/src/components/actions/item-action-menu.tsx +++ b/packages/compass-components/src/components/actions/item-action-menu.tsx @@ -61,7 +61,7 @@ export function ItemActionMenu({ const menuTriggerRef = useRef(null); const [isMenuOpen, setIsMenuOpen] = useState(false); - const onClick = useCallback( + const onClick: React.MouseEventHandler = useCallback( (evt) => { evt.stopPropagation(); if (evt.currentTarget.dataset.menuitem) { @@ -69,7 +69,11 @@ export function ItemActionMenu({ // Workaround for https://jira.mongodb.org/browse/PD-1674 menuTriggerRef.current?.focus(); } - onAction(evt.currentTarget.dataset.action); + const actionName = evt.currentTarget.dataset.action; + if (typeof actionName !== 'string') { + throw new Error('Expected element to have a "data-action" attribute'); + } + onAction(actionName as Action); }, [onAction] );