Skip to content

Commit 6d93761

Browse files
authored
Merge branch 'main' into dependabot/github_actions/minor-and-patch-6bbbf9925a
2 parents 3d9c250 + e9596f9 commit 6d93761

6 files changed

Lines changed: 40 additions & 39 deletions

File tree

.changeset/slow-colts-pick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aragon/gov-ui-kit': minor
3+
---
4+
5+
Update `DataListItem` component to wrap in `div` when non-interactive

src/core/components/dataList/dataListContainer/dataListContainerSkeletonLoader.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ export interface IDataListContainerSkeletonLoaderProps {}
44

55
export const DataListContainerSkeletonLoader: React.FC<IDataListContainerSkeletonLoaderProps> = () => {
66
return (
7-
<DataListItem className="flex animate-pulse flex-col gap-3">
7+
<DataListItem
8+
className="flex animate-pulse flex-col gap-3 py-4 md:py-6"
9+
tabIndex={0}
10+
aria-busy="true"
11+
aria-label="loading"
12+
>
813
<div className="h-5 w-1/3 rounded-full bg-neutral-50" />
914
<div className="flex flex-col gap-1.5">
1015
<div className="h-4 grow rounded-full bg-neutral-50" />

src/core/components/dataList/dataListItem/dataListItem.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Story = StoryObj<typeof DataList.Item>;
2020
export const Default: Story = {
2121
args: {
2222
children: 'Data list item',
23-
className: 'min-h-12',
23+
className: 'flex items-center min-h-12',
2424
},
2525
};
2626

src/core/components/dataList/dataListItem/dataListItem.test.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,6 @@ describe('<DataList.Item /> component', () => {
3131
expect(link.classList).toContain('cursor-pointer');
3232
});
3333

34-
it('marks the item as hidden when the data list is on initialLoading state', () => {
35-
const context = { state: 'initialLoading' as const };
36-
const props = { href: '/test' };
37-
render(createTestComponent({ context, props }));
38-
expect(screen.queryByRole('link')).not.toBeInTheDocument();
39-
});
40-
41-
it('marks the item as hidden when the data list is on loading state with no elements being currently rendered', () => {
42-
const context = { state: 'loading' as const, childrenItemCount: 0 };
43-
const props = { href: '/test' };
44-
render(createTestComponent({ context, props }));
45-
expect(screen.queryByRole('link')).not.toBeInTheDocument();
46-
});
47-
4834
it('does not throw error when not placed inside the DataListContextProvider', () => {
4935
const context = null;
5036
expect(() => render(createTestComponent({ context }))).not.toThrow();
@@ -58,9 +44,22 @@ describe('<DataList.Item /> component', () => {
5844
expect(button.classList).toContain('cursor-pointer');
5945
});
6046

61-
it('renders the item as a non interactive button when both onClick and href property are not set', () => {
62-
const props = { onClick: undefined, href: undefined };
47+
it('renders the item as a non interactive div when both onClick and href property are not set', () => {
48+
const props = { children: 'test-data-list-item', onClick: undefined, href: undefined };
49+
render(createTestComponent({ props }));
50+
const button = screen.queryByRole('button', { name: props.children });
51+
const link = screen.queryByRole('link', { name: props.children });
52+
const text = screen.getByText(props.children);
53+
expect(button).not.toBeInTheDocument();
54+
expect(link).not.toBeInTheDocument();
55+
expect(text).toBeInTheDocument();
56+
});
57+
58+
it('renders the item as an interactive button when onClick property is set', () => {
59+
const props = { children: 'test-data-list-item', onClick: jest.fn() };
6360
render(createTestComponent({ props }));
64-
expect(screen.getByRole('button').classList).not.toContain('cursor-pointer');
61+
const button = screen.getByRole('button', { name: props.children });
62+
expect(button).toBeInTheDocument();
63+
expect(button.classList).toContain('cursor-pointer');
6564
});
6665
});
Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
import classNames from 'classnames';
2-
import { type AnchorHTMLAttributes, type ButtonHTMLAttributes, useContext } from 'react';
2+
import { type AnchorHTMLAttributes, type ButtonHTMLAttributes, type HTMLAttributes } from 'react';
33
import { LinkBase } from '../../link';
4-
import { dataListContext } from '../dataListContext';
54

6-
export type IDataListItemProps = ButtonHTMLAttributes<HTMLButtonElement> | AnchorHTMLAttributes<HTMLAnchorElement>;
5+
export type IDataListItemProps =
6+
| ButtonHTMLAttributes<HTMLButtonElement>
7+
| AnchorHTMLAttributes<HTMLAnchorElement>
8+
| HTMLAttributes<HTMLDivElement>;
79

810
export const DataListItem: React.FC<IDataListItemProps> = (props) => {
911
const { className, ...otherProps } = props;
1012

11-
// Use the dataListContext directly to support usage of DataListItem component outside the DataListContextProvider.
12-
const { state, childrenItemCount } = useContext(dataListContext) ?? {};
13-
14-
// The DataListElement is a skeleton element on initial loading or loading state when no items are being
15-
// rendered (e.g. after a reset filters action)
16-
const isSkeletonElement = state === 'initialLoading' || (state === 'loading' && childrenItemCount === 0);
17-
1813
const isLinkElement = 'href' in otherProps && otherProps.href != null && otherProps.href !== '';
19-
const isInteractiveElement = !isSkeletonElement && (isLinkElement || props.onClick != null);
14+
const isInteractiveElement = isLinkElement || props.onClick != null;
2015

2116
const actionItemClasses = classNames(
2217
'w-full rounded-xl border border-neutral-100 bg-neutral-0 px-4 text-left shadow-neutral-sm transition-all', // Default
@@ -27,17 +22,15 @@ export const DataListItem: React.FC<IDataListItemProps> = (props) => {
2722
className,
2823
);
2924

30-
const commonProps = {
31-
className: actionItemClasses,
32-
'aria-hidden': isSkeletonElement,
33-
tabIndex: isSkeletonElement ? -1 : 0,
34-
};
25+
if (isLinkElement) {
26+
return <LinkBase className={actionItemClasses} {...otherProps} />;
27+
}
3528

36-
if (!isLinkElement) {
29+
if (isInteractiveElement) {
3730
const { type = 'button', ...buttonProps } = otherProps as ButtonHTMLAttributes<HTMLButtonElement>;
3831

39-
return <button type={type} {...commonProps} {...buttonProps} />;
32+
return <button type={type} className={actionItemClasses} {...buttonProps} />;
4033
}
4134

42-
return <LinkBase {...commonProps} {...otherProps} />;
35+
return <div className={actionItemClasses} {...(otherProps as HTMLAttributes<HTMLDivElement>)} />;
4336
};

src/modules/components/proposal/proposalDataListItem/proposalDataListItemStructure/proposalDataListItemStructure.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export const ProposalDataListItemStructure: React.FC<IProposalDataListItemStruct
2222
wagmiConfig: config,
2323
id,
2424
className,
25-
type,
2625
date,
2726
tag,
2827
publisher,

0 commit comments

Comments
 (0)