Commit 38daf0cb by kay delaney Committed by GitHub

UI/Card: Fix handling of 'onClick' callback (#31225)

parent 350dcb99
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { Card } from './Card';
describe('Card', () => {
it('should execute callback when clicked', () => {
const callback = jest.fn();
render(<Card heading="Test Heading" onClick={callback} />);
fireEvent.click(screen.getByText('Test Heading'));
expect(callback).toBeCalledTimes(1);
});
});
...@@ -101,7 +101,7 @@ export const Card: CardInterface = ({ ...@@ -101,7 +101,7 @@ export const Card: CardInterface = ({
const disableEvents = disabled && !actions; const disableEvents = disabled && !actions;
const containerStyles = getContainerStyles(theme, disableEvents, disableHover); const containerStyles = getContainerStyles(theme, disableEvents, disableHover);
const onCardClick = useCallback(() => (disableHover ? () => {} : onClick), [disableHover, onClick]); const onCardClick = useCallback(() => (disableHover ? () => {} : onClick?.()), [disableHover, onClick]);
return ( return (
<CardContainer <CardContainer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment