Skip to content

Commit

Permalink
feat(Card): enable onClick event handler on selected card (#1840)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaryaLari authored Sep 12, 2024
1 parent 11cdcf8 commit a1678b6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/Card/Card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ $block: '.#{variables.$ns}card';
&:hover {
--_--border-color: transparent;

&::before {
&:not(#{$block}_selected)::before {
content: '';
border: 2px solid var(--g-color-line-brand);
opacity: 0.5;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const Card = React.forwardRef<HTMLDivElement, CardProps>(function Card(pr

/* Clickable card — only with type 'action' or 'selection' and not selected or disabled */
const hasAction = isTypeAction || isTypeSelection;
const isClickable = hasAction && Boolean(onClick) && !(disabled || selected);
const isClickable = hasAction && Boolean(onClick) && !disabled;

/* Theme only with type 'container' */
const defaultTheme = isTypeContainer ? 'normal' : undefined;
Expand Down
15 changes: 15 additions & 0 deletions src/components/Card/__tests__/Card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ describe('Card', () => {
expect(handleOnClick).toHaveBeenCalledTimes(1);
});

test('call onClick if type="selection" & selected', async () => {
const user = userEvent.setup();
const handleOnClick = jest.fn();
render(
<Card type="selection" selected onClick={handleOnClick} qa={qaId}>
{cardText}
</Card>,
);

const card = screen.getByText(cardText);

await user.click(card);
expect(handleOnClick).toHaveBeenCalledTimes(1);
});

test('ignore onClick if type!="container"', async () => {
const user = userEvent.setup();
const handleOnClick = jest.fn();
Expand Down

0 comments on commit a1678b6

Please sign in to comment.