Skip to content
Open
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
11 changes: 11 additions & 0 deletions packages/react-table/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export interface TableProps extends React.HTMLProps<HTMLTableElement>, OUIAProps
role?: string;
/** @beta Flag indicating if the table should have plain styling with a transparent background */
isPlain?: boolean;
/** @beta Flag indicating if the table should not have plain styling when in the glass theme. If isPlain is also set, this property will be ignored. */
isNoPlainOnGlass?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe isPlainOnGlass is more accurate since setting it to true removes the modifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting it to true is what sets the no-plain modifier.

/** If set to true, the table header sticks to the top of its container */
isStickyHeader?: boolean;
/** @hide Forwarded ref */
Expand Down Expand Up @@ -97,6 +99,7 @@ const TableBase: React.FunctionComponent<TableProps> = ({
borders = true,
isStickyHeader = false,
isPlain = false,
isNoPlainOnGlass = false,
gridBreakPoint = TableGridBreakpoint.gridMd,
'aria-label': ariaLabel,
role = 'grid',
Expand All @@ -121,6 +124,13 @@ const TableBase: React.FunctionComponent<TableProps> = ({
const [hasSelectableRows, setHasSelectableRows] = useState(false);
const [tableCaption, setTableCaption] = useState<React.JSX.Element | undefined>();

if (isPlain && isNoPlainOnGlass) {
// eslint-disable-next-line no-console
console.warn(
"Table: When both isPlain and isNoPlainOnGlass are true, isPlain will take precedence and isNoPlainOnGlass will have no effect. It's recommended to pass only one prop according to the current theme."
);
}

useEffect(() => {
document.addEventListener('keydown', handleKeys);

Expand Down Expand Up @@ -226,6 +236,7 @@ const TableBase: React.FunctionComponent<TableProps> = ({
isStriped && styles.modifiers.striped,
isExpandable && styles.modifiers.expandable,
isPlain && styles.modifiers.plain,
isNoPlainOnGlass && styles.modifiers.noPlain,
hasNoInset && stylesTreeView.modifiers.noInset,
isNested && 'pf-m-nested',
hasAnimations && styles.modifiers.animateExpand
Expand Down
30 changes: 30 additions & 0 deletions packages/react-table/src/components/Table/__tests__/Table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,33 @@ test(`Renders with class ${styles.modifiers.plain} when isPlain is true`, () =>

expect(screen.getByRole('grid', { name: 'Test table' })).toHaveClass(styles.modifiers.plain);
});

test(`Does not render with class ${styles.modifiers.plain} when isPlain is not defined`, () => {
render(<Table aria-label="Test table" />);

expect(screen.getByRole('grid', { name: 'Test table' })).not.toHaveClass(styles.modifiers.plain);
});

test(`Does not render with class ${styles.modifiers.plain} when isPlain is false`, () => {
render(<Table isPlain={false} aria-label="Test table" />);

expect(screen.getByRole('grid', { name: 'Test table' })).not.toHaveClass(styles.modifiers.plain);
});

test(`Renders with class ${styles.modifiers.noPlain} when isNoPlainOnGlass is true`, () => {
render(<Table isNoPlainOnGlass aria-label="Test table" />);

expect(screen.getByRole('grid', { name: 'Test table' })).toHaveClass(styles.modifiers.noPlain);
});

test(`Does not render with class ${styles.modifiers.noPlain} when isNoPlainOnGlass is undefined`, () => {
render(<Table aria-label="Test table" />);

expect(screen.getByRole('grid', { name: 'Test table' })).not.toHaveClass(styles.modifiers.noPlain);
});

test(`Does not render with class ${styles.modifiers.noPlain} when isNoPlainOnGlass is false`, () => {
render(<Table isNoPlainOnGlass={false} aria-label="Test table" />);

expect(screen.getByRole('grid', { name: 'Test table' })).not.toHaveClass(styles.modifiers.noPlain);
});
Loading