Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@clayui/core):LPD 39956 Clay Table with nested rows shows expand button when children is empty array. #5884

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/clay-core/src/table/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ function* flatten<T extends Record<string, any>>(
_size: array.length,
} as unknown as T;

if (Array.isArray(array[i]![nestedKey])) {
if (
Array.isArray(array[i]![nestedKey]) &&
array[i]![nestedKey].length > 0
) {
delete item[nestedKey];
// @ts-ignore
item._expandable = true;
Expand Down
44 changes: 44 additions & 0 deletions packages/clay-core/src/table/__tests__/IncrementalInteractions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ const itemsTree = [
},
];

const emptyStateItems = [
{
id: 1,
name: 'Foo',
type: 'PNG',
},
{id: 2, name: 'Bar', type: 'Files'},
{
children: [],
id: 3,
name: 'Baz',
type: 'Folder',
},
];

describe('Table incremental interactions', () => {
afterEach(cleanup);

Expand Down Expand Up @@ -479,6 +494,35 @@ describe('Table incremental interactions', () => {
expect(thirdRow!.getAttribute('aria-expanded')).toBe('false');
});

it('does not render left arrow button when child array is empty', () => {
const {queryByRole} = render(
<Table columnsVisibility={false} nestedKey="children">
<Head items={columns}>
{(column) => (
<Cell key={column.id}>{column.name}</Cell>
)}
</Head>

<Body defaultItems={emptyStateItems}>
{(row) => (
<Row items={columns}>
{(column) => (
<Cell key={`${row.id}:${column.id}`}>
{/** @ts-ignore */}
{row[column.id]}
</Cell>
)}
</Row>
)}
</Body>
</Table>
);

const buttonRole = queryByRole('presentation');

expect(buttonRole).not.toBeInTheDocument();
});

it('pressing the left arrow key moves the focus to the row on the level above', () => {
const {getAllByRole} = render(
<Table columnsVisibility={false} nestedKey="children">
Expand Down
Loading