From f523a5eb32ad5bca4506f45fa276c02a7b7b2c89 Mon Sep 17 00:00:00 2001 From: Milos Dzepina Date: Thu, 12 Jun 2025 15:57:48 +0100 Subject: [PATCH 1/5] Update DataListItem to wrap in div when non interactive Signed-off-by: Milos Dzepina --- .../dataListItem/dataListItem.test.tsx | 19 ++++++++++++++++--- .../dataList/dataListItem/dataListItem.tsx | 15 +++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/core/components/dataList/dataListItem/dataListItem.test.tsx b/src/core/components/dataList/dataListItem/dataListItem.test.tsx index 4a7ae7462..9f0b28f60 100644 --- a/src/core/components/dataList/dataListItem/dataListItem.test.tsx +++ b/src/core/components/dataList/dataListItem/dataListItem.test.tsx @@ -58,9 +58,22 @@ describe(' component', () => { expect(button.classList).toContain('cursor-pointer'); }); - it('renders the item as a non interactive button when both onClick and href property are not set', () => { - const props = { onClick: undefined, href: undefined }; + it('renders the item as a non interactive div when both onClick and href property are not set', () => { + const props = { children: 'test-data-list-item', onClick: undefined, href: undefined }; render(createTestComponent({ props })); - expect(screen.getByRole('button').classList).not.toContain('cursor-pointer'); + const button = screen.queryByRole('button', { name: props.children }); + const link = screen.queryByRole('link', { name: props.children }); + const text = screen.getByText(props.children); + expect(button).not.toBeInTheDocument(); + expect(link).not.toBeInTheDocument(); + expect(text).toBeInTheDocument(); + }); + + it('renders the item as an interactive button when onClick property is set', () => { + const props = { children: 'test-data-list-item', onClick: jest.fn() }; + render(createTestComponent({ props })); + const button = screen.getByRole('button', { name: props.children }); + expect(button).toBeInTheDocument(); + expect(button.classList).toContain('cursor-pointer'); }); }); diff --git a/src/core/components/dataList/dataListItem/dataListItem.tsx b/src/core/components/dataList/dataListItem/dataListItem.tsx index 38da467ac..bb231770f 100644 --- a/src/core/components/dataList/dataListItem/dataListItem.tsx +++ b/src/core/components/dataList/dataListItem/dataListItem.tsx @@ -1,9 +1,12 @@ import classNames from 'classnames'; -import { type AnchorHTMLAttributes, type ButtonHTMLAttributes, useContext } from 'react'; +import { type AnchorHTMLAttributes, type ButtonHTMLAttributes, type HTMLAttributes, useContext } from 'react'; import { LinkBase } from '../../link'; import { dataListContext } from '../dataListContext'; -export type IDataListItemProps = ButtonHTMLAttributes | AnchorHTMLAttributes; +export type IDataListItemProps = + | ButtonHTMLAttributes + | AnchorHTMLAttributes + | HTMLAttributes; export const DataListItem: React.FC = (props) => { const { className, ...otherProps } = props; @@ -33,11 +36,15 @@ export const DataListItem: React.FC = (props) => { tabIndex: isSkeletonElement ? -1 : 0, }; - if (!isLinkElement) { + if (isLinkElement) { + return ; + } + + if (isInteractiveElement) { const { type = 'button', ...buttonProps } = otherProps as ButtonHTMLAttributes; return