Skip to content

Commit ea5f4bb

Browse files
authored
Merge pull request #973 from platex-rehor-bot/bot/PF-4546
feat(SkeletonTable): add hasHeader prop
2 parents 6753497 + a32b5e1 commit ea5f4bb

4 files changed

Lines changed: 37 additions & 8 deletions

File tree

packages/module/patternfly-docs/content/extensions/component-groups/examples/SkeletonTable/SkeletonTable.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ To simulate this loading process, click the "Reload table" button and wait for t
7474

7575
```
7676

77+
### Without header
78+
79+
To render a skeleton table without a header (for example, when the real table header is already rendered above the loading state), set the `hasHeader` prop to `false`.
80+
81+
```js file="./SkeletonTableNoHeaderExample.tsx"
82+
83+
```
84+
7785
### Skeleton table head
7886

7987
You can render only the `<Thead>` part of the skeleton table by using the `<SkeletonTableHead/>`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { FC } from 'react';
2+
import SkeletonTable from '@patternfly/react-component-groups/dist/dynamic/SkeletonTable';
3+
4+
export const SkeletonTableNoHeaderExample: FC = () => <SkeletonTable columnsCount={3} rowsCount={5} hasHeader={false} />;

packages/module/src/SkeletonTable/SkeletonTable.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,16 @@ describe('SkeletonTable component', () => {
99
it('should render correctly with rows', () => {
1010
expect(render(<SkeletonTable columns={[ 'First', 'Second' ]} rows={10} />)).toMatchSnapshot();
1111
});
12+
13+
it('should render without header when hasHeader is false', () => {
14+
const { container } = render(<SkeletonTable columnsCount={2} hasHeader={false} />);
15+
expect(container.querySelectorAll('thead')).toHaveLength(0);
16+
expect(container.querySelectorAll('tbody')).toHaveLength(1);
17+
});
18+
19+
it('should render with header by default', () => {
20+
const { container } = render(<SkeletonTable columnsCount={2} />);
21+
expect(container.querySelectorAll('thead')).toHaveLength(1);
22+
expect(container.querySelectorAll('tbody')).toHaveLength(1);
23+
});
1224
});

packages/module/src/SkeletonTable/SkeletonTable.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export interface SkeletonTableProps
2828
columns?: (ReactNode | { cell: ReactNode; props?: ThProps })[];
2929
/** Number of columns in the table */
3030
columnsCount?: number;
31+
/** Flag indicating if the table header skeleton should be rendered */
32+
hasHeader?: boolean;
3133
}
3234

3335
const SkeletonTable: FunctionComponent<SkeletonTableProps> = ({
@@ -42,21 +44,24 @@ const SkeletonTable: FunctionComponent<SkeletonTableProps> = ({
4244
columns,
4345
columnsCount,
4446
isTreeTable,
47+
hasHeader = true,
4548
...rest
4649
}: SkeletonTableProps) => {
4750
const rowCellsCount = Array.isArray(columns) ? columns.length : columnsCount;
4851

4952
return (
5053
<Table aria-label="Loading" variant={variant} borders={borders} ouiaId={ouiaId} {...rest}>
5154
{caption && <Caption>{caption}</Caption>}
52-
<SkeletonTableHead
53-
ouiaId={ouiaId}
54-
isSelectable={isSelectable}
55-
isExpandable={isExpandable}
56-
columnsCount={columnsCount}
57-
columns={columns}
58-
isTreeTable={isTreeTable}
59-
/>
55+
{hasHeader && (
56+
<SkeletonTableHead
57+
ouiaId={ouiaId}
58+
isSelectable={isSelectable}
59+
isExpandable={isExpandable}
60+
columnsCount={columnsCount}
61+
columns={columns}
62+
isTreeTable={isTreeTable}
63+
/>
64+
)}
6065
<SkeletonTableBody
6166
columnsCount={rowCellsCount ?? 0}
6267
rowsCount={rowsCount}

0 commit comments

Comments
 (0)