Skip to content

Commit c4ea313

Browse files
committed
feat(Data list): Add isNoPlainOnGlass prop to add pf-m-no-plain modifier to the data list
1 parent 641c888 commit c4ea313

File tree

6 files changed

+75
-26
lines changed

6 files changed

+75
-26
lines changed

packages/react-core/src/components/DataList/DataList.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,29 @@ export enum DataListWrapModifier {
1919
}
2020

2121
export interface DataListProps extends React.HTMLProps<HTMLUListElement> {
22-
/** Content rendered inside the DataList list */
22+
/** Content rendered inside the data list list */
2323
children?: React.ReactNode;
24-
/** Additional classes added to the DataList list */
24+
/** Additional classes added to the data list list */
2525
className?: string;
26-
/** Adds accessible text to the DataList list */
26+
/** Adds accessible text to the data list list */
2727
'aria-label': string;
28-
/** Optional callback to make DataList selectable, fired when DataListItem selected */
28+
/** Optional callback to make data list selectable, fired when data list item selected */
2929
onSelectDataListItem?: (event: React.MouseEvent | React.KeyboardEvent, id: string) => void;
30-
/** Id of DataList item currently selected */
30+
/** Id of data list item currently selected */
3131
selectedDataListItemId?: string;
32-
/** Flag indicating if DataList should have compact styling */
32+
/** Flag indicating if data list should have compact styling */
3333
isCompact?: boolean;
34-
/** @beta Flag indicating if DataList should have plain styling with a transparent background */
34+
/** @beta Flag indicating if data list should have plain styling with a transparent background */
3535
isPlain?: boolean;
36+
/** @beta Flag to prevent the data list from automatically applying plain styling when glass theme is enabled. When both this and isPlain are true, isPlain takes precedence. */
37+
isNoPlainOnGlass?: boolean;
3638
/** Specifies the grid breakpoints */
3739
gridBreakpoint?: 'none' | 'always' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
38-
/** Determines which wrapping modifier to apply to the DataList */
40+
/** Determines which wrapping modifier to apply to the data list */
3941
wrapModifier?: DataListWrapModifier | 'nowrap' | 'truncate' | 'breakWord';
4042
/** Object that causes the data list to render hidden inputs which improve selectable item a11y */
4143
onSelectableRowChange?: (event: React.FormEvent<HTMLInputElement>, id: string) => void;
42-
/** @hide custom ref of the DataList */
44+
/** @hide custom ref of the data list */
4345
innerRef?: React.RefObject<HTMLUListElement | null>;
4446
}
4547

@@ -62,12 +64,20 @@ export const DataListBase: React.FunctionComponent<DataListProps> = ({
6264
selectedDataListItemId = '',
6365
isCompact = false,
6466
isPlain = false,
67+
isNoPlainOnGlass = false,
6568
gridBreakpoint = 'md',
6669
wrapModifier = null,
6770
onSelectableRowChange,
6871
innerRef,
6972
...props
7073
}: DataListProps) => {
74+
if (isPlain && isNoPlainOnGlass) {
75+
// eslint-disable-next-line no-console
76+
console.warn(
77+
`DataList: 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.`
78+
);
79+
}
80+
7181
const isSelectable = onSelectDataListItem !== undefined;
7282

7383
const updateSelectedDataListItem = (event: React.MouseEvent | React.KeyboardEvent, id: string) => {
@@ -88,6 +98,7 @@ export const DataListBase: React.FunctionComponent<DataListProps> = ({
8898
styles.dataList,
8999
isCompact && styles.modifiers.compact,
90100
isPlain && styles.modifiers.plain,
101+
isNoPlainOnGlass && styles.modifiers.noPlain,
91102
gridBreakpointClasses[gridBreakpoint],
92103
wrapModifier && styles.modifiers[wrapModifier],
93104
className

packages/react-core/src/components/DataList/DataListAction.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import styles from '@patternfly/react-styles/css/components/DataList/data-list';
33
import { formatBreakpointMods } from '../../helpers/util';
44

55
export interface DataListActionProps extends Omit<React.HTMLProps<HTMLDivElement>, 'children'> {
6-
/** Content rendered as DataList Action (e.g <Button> or <Dropdown>) */
6+
/** Content rendered as data list action (e.g <Button> or <Dropdown>) */
77
children: React.ReactNode;
8-
/** Additional classes added to the DataList Action */
8+
/** Additional classes added to the data list action */
99
className?: string;
10-
/** Identify the DataList toggle number */
10+
/** Identify the data list toggle number */
1111
id: string;
12-
/** Adds accessible text to the DataList Action */
12+
/** Adds accessible text to the data list action */
1313
'aria-labelledby': string;
14-
/** Adds accessible text to the DataList Action */
14+
/** Adds accessible text to the data list action */
1515
'aria-label': string;
1616
/** What breakpoints to hide/show the data list action */
1717
visibility?: {

packages/react-core/src/components/DataList/DataListCell.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import { DataListWrapModifier } from './DataList';
55
import { Tooltip } from '../Tooltip';
66

77
export interface DataListCellProps extends Omit<React.HTMLProps<HTMLDivElement>, 'width'> {
8-
/** Content rendered inside the DataList cell */
8+
/** Content rendered inside the data list cell */
99
children?: React.ReactNode;
10-
/** Additional classes added to the DataList cell */
10+
/** Additional classes added to the data list cell */
1111
className?: string;
12-
/** Width (from 1-5) to the DataList cell */
12+
/** Width (from 1-5) to the data list cell */
1313
width?: 1 | 2 | 3 | 4 | 5;
14-
/** Enables the body Content to fill the height of the card */
14+
/** Enables the body content to fill the height of the card */
1515
isFilled?: boolean;
1616
/** Aligns the cell content to the right of its parent. */
1717
alignRight?: boolean;
18-
/** Set to true if the cell content is an Icon */
18+
/** Set to true if the cell content is an icon */
1919
isIcon?: boolean;
20-
/** Determines which wrapping modifier to apply to the DataListCell */
20+
/** Determines which wrapping modifier to apply to the data list cell */
2121
wrapModifier?: DataListWrapModifier | 'nowrap' | 'truncate' | 'breakWord';
2222
}
2323

packages/react-core/src/components/DataList/DataListItemCells.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { css } from '@patternfly/react-styles';
22
import styles from '@patternfly/react-styles/css/components/DataList/data-list';
33

44
export interface DataListItemCellsProps extends React.HTMLProps<HTMLDivElement> {
5-
/** Additional classes added to the DataList item Content Wrapper. Children should be one ore more <DataListCell> nodes */
5+
/** Additional classes added to the data list item content wrapper. Children should be one ore more <DataListCell> nodes */
66
className?: string;
77
/** Array of <DataListCell> nodes that are rendered one after the other. */
88
dataListCells?: React.ReactNode;

packages/react-core/src/components/DataList/DataListToggle.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import styles from '@patternfly/react-styles/css/components/DataList/data-list';
44
import { Button, ButtonProps, ButtonVariant } from '../Button';
55

66
export interface DataListToggleProps extends React.HTMLProps<HTMLDivElement> {
7-
/** Additional classes added to the DataList cell */
7+
/** Additional classes added to the data list cell */
88
className?: string;
9-
/** Flag to show if the expanded content of the DataList item is visible */
9+
/** Flag to show if the expanded content of the data list item is visible */
1010
isExpanded?: boolean;
11-
/** Identify the DataList toggle number */
11+
/** Identify the data list toggle number */
1212
id: string;
1313
/** Id for the row */
1414
rowid?: string;
15-
/** Adds accessible text to the DataList toggle */
15+
/** Adds accessible text to the data list toggle */
1616
'aria-labelledby'?: string;
17-
/** Adds accessible text to the DataList toggle */
17+
/** Adds accessible text to the data list toggle */
1818
'aria-label'?: string;
1919
/** Allows users of some screen readers to shift focus to the controlled element. Should be used when the controlled contents are not adjacent to the toggle that controls them. */
2020
'aria-controls'?: string;

packages/react-core/src/components/DataList/__tests__/DataList.test.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '@testing-library/jest-dom';
12
import { render, screen } from '@testing-library/react';
23
import userEvent from '@testing-library/user-event';
34

@@ -77,6 +78,43 @@ test(`Renders with class ${styles.modifiers.plain} when isPlain is true`, () =>
7778
expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.plain);
7879
});
7980

81+
test(`Renders with ${styles.modifiers.noPlain} when isNoPlainOnGlass is true`, () => {
82+
render(<DataList aria-label="list" isNoPlainOnGlass />);
83+
expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.noPlain);
84+
});
85+
86+
test('Warns when both isPlain and isNoPlainOnGlass are true', () => {
87+
const warnSpy = jest.spyOn(global.console, 'warn').mockImplementation(() => {});
88+
89+
render(<DataList aria-label="list" isPlain isNoPlainOnGlass />);
90+
91+
expect(warnSpy).toHaveBeenCalledWith(
92+
`DataList: 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.`
93+
);
94+
95+
warnSpy.mockRestore();
96+
});
97+
98+
test('Does not warn when only isPlain is true', () => {
99+
const warnSpy = jest.spyOn(global.console, 'warn').mockImplementation(() => {});
100+
101+
render(<DataList aria-label="list" isPlain />);
102+
103+
expect(warnSpy).not.toHaveBeenCalled();
104+
105+
warnSpy.mockRestore();
106+
});
107+
108+
test('Does not warn when only isNoPlainOnGlass is true', () => {
109+
const warnSpy = jest.spyOn(global.console, 'warn').mockImplementation(() => {});
110+
111+
render(<DataList aria-label="list" isNoPlainOnGlass />);
112+
113+
expect(warnSpy).not.toHaveBeenCalled();
114+
115+
warnSpy.mockRestore();
116+
});
117+
80118
test('Renders with a hidden input to improve a11y when onSelectableRowChange is passed', () => {
81119
render(
82120
<DataList aria-label="this is a simple list" onSelectableRowChange={() => {}}>

0 commit comments

Comments
 (0)