@patternfly/react-core 4.198.12 → 4.198.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/esm/components/Label/Label.d.ts.map +1 -1
- package/dist/esm/components/Label/Label.js +5 -2
- package/dist/esm/components/Label/Label.js.map +1 -1
- package/dist/esm/components/Menu/MenuItem.d.ts +3 -1
- package/dist/esm/components/Menu/MenuItem.d.ts.map +1 -1
- package/dist/esm/components/Menu/MenuItem.js +4 -3
- package/dist/esm/components/Menu/MenuItem.js.map +1 -1
- package/dist/esm/components/Nav/NavGroup.d.ts +1 -1
- package/dist/esm/components/Nav/NavGroup.d.ts.map +1 -1
- package/dist/esm/components/Nav/NavGroup.js +7 -2
- package/dist/esm/components/Nav/NavGroup.js.map +1 -1
- package/dist/esm/components/Toolbar/Toolbar.d.ts +3 -1
- package/dist/esm/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/esm/components/Toolbar/Toolbar.js +4 -3
- package/dist/esm/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/esm/components/Toolbar/ToolbarChipGroupContent.d.ts +2 -0
- package/dist/esm/components/Toolbar/ToolbarChipGroupContent.d.ts.map +1 -1
- package/dist/esm/components/Toolbar/ToolbarChipGroupContent.js +4 -3
- package/dist/esm/components/Toolbar/ToolbarChipGroupContent.js.map +1 -1
- package/dist/esm/components/Toolbar/ToolbarExpandableContent.d.ts.map +1 -1
- package/dist/esm/components/Toolbar/ToolbarExpandableContent.js +4 -3
- package/dist/esm/components/Toolbar/ToolbarExpandableContent.js.map +1 -1
- package/dist/esm/components/Toolbar/ToolbarUtils.d.ts +1 -0
- package/dist/esm/components/Toolbar/ToolbarUtils.d.ts.map +1 -1
- package/dist/esm/components/Toolbar/ToolbarUtils.js.map +1 -1
- package/dist/js/components/Label/Label.d.ts.map +1 -1
- package/dist/js/components/Label/Label.js +5 -2
- package/dist/js/components/Label/Label.js.map +1 -1
- package/dist/js/components/Menu/MenuItem.d.ts +3 -1
- package/dist/js/components/Menu/MenuItem.d.ts.map +1 -1
- package/dist/js/components/Menu/MenuItem.js +4 -4
- package/dist/js/components/Menu/MenuItem.js.map +1 -1
- package/dist/js/components/Nav/NavGroup.d.ts +1 -1
- package/dist/js/components/Nav/NavGroup.d.ts.map +1 -1
- package/dist/js/components/Nav/NavGroup.js +7 -2
- package/dist/js/components/Nav/NavGroup.js.map +1 -1
- package/dist/js/components/Toolbar/Toolbar.d.ts +3 -1
- package/dist/js/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/js/components/Toolbar/Toolbar.js +4 -3
- package/dist/js/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/js/components/Toolbar/ToolbarChipGroupContent.d.ts +2 -0
- package/dist/js/components/Toolbar/ToolbarChipGroupContent.d.ts.map +1 -1
- package/dist/js/components/Toolbar/ToolbarChipGroupContent.js +4 -3
- package/dist/js/components/Toolbar/ToolbarChipGroupContent.js.map +1 -1
- package/dist/js/components/Toolbar/ToolbarExpandableContent.d.ts.map +1 -1
- package/dist/js/components/Toolbar/ToolbarExpandableContent.js +4 -3
- package/dist/js/components/Toolbar/ToolbarExpandableContent.js.map +1 -1
- package/dist/js/components/Toolbar/ToolbarUtils.d.ts +1 -0
- package/dist/js/components/Toolbar/ToolbarUtils.d.ts.map +1 -1
- package/dist/js/components/Toolbar/ToolbarUtils.js.map +1 -1
- package/dist/umd/react-core.js +28 -16
- package/dist/umd/react-core.min.js +1 -1
- package/package.json +5 -5
- package/src/components/Label/Label.tsx +5 -2
- package/src/components/Menu/MenuItem.tsx +9 -1
- package/src/components/Menu/examples/Menu.md +57 -32
- package/src/components/Nav/NavGroup.tsx +20 -9
- package/src/components/Nav/examples/Nav.md +2 -0
- package/src/components/Toolbar/Toolbar.tsx +7 -2
- package/src/components/Toolbar/ToolbarChipGroupContent.tsx +5 -1
- package/src/components/Toolbar/ToolbarExpandableContent.tsx +3 -2
- package/src/components/Toolbar/ToolbarUtils.tsx +1 -0
- package/src/components/Toolbar/__tests__/ToolbarToggleGroup.test.tsx +71 -1
- package/src/components/Toolbar/__tests__/__snapshots__/ToolbarToggleGroup.test.tsx.snap +394 -0
- package/src/components/Toolbar/examples/Toolbar.md +8 -1
- package/src/components/Toolbar/examples/ToolbarCustomChipGroupContent.tsx +166 -0
- package/src/demos/Nav.md +7 -3
- package/src/demos/NotificationDrawer/NotificationDrawer.md +5 -2
- package/src/demos/Page/Page.md +7 -3
- package/src/demos/examples/DashboardHeader.js +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.198.
|
|
3
|
+
"version": "4.198.13",
|
|
4
4
|
"description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"generate": "node scripts/copyStyles.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@patternfly/react-icons": "^4.49.
|
|
38
|
-
"@patternfly/react-styles": "^4.48.
|
|
39
|
-
"@patternfly/react-tokens": "^4.50.
|
|
37
|
+
"@patternfly/react-icons": "^4.49.13",
|
|
38
|
+
"@patternfly/react-styles": "^4.48.13",
|
|
39
|
+
"@patternfly/react-tokens": "^4.50.13",
|
|
40
40
|
"focus-trap": "6.2.2",
|
|
41
41
|
"react-dropzone": "9.0.0",
|
|
42
42
|
"tippy.js": "5.1.2",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"react": "^16.8.0 || ^17.0.0",
|
|
61
61
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "54e64ae9d634521ab81f085c6c1c0aa503d2a123"
|
|
64
64
|
}
|
|
@@ -197,8 +197,11 @@ export const Label: React.FunctionComponent<LabelProps> = ({
|
|
|
197
197
|
const componentRef = React.useRef();
|
|
198
198
|
const [isTooltipVisible, setIsTooltipVisible] = React.useState(false);
|
|
199
199
|
useIsomorphicLayoutEffect(() => {
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
const currTextRef = isEditable ? editableButtonRef : textRef;
|
|
201
|
+
if (!isEditableActive) {
|
|
202
|
+
setIsTooltipVisible(currTextRef.current && currTextRef.current.offsetWidth < currTextRef.current.scrollWidth);
|
|
203
|
+
}
|
|
204
|
+
}, [isEditableActive]);
|
|
202
205
|
const content = (
|
|
203
206
|
<React.Fragment>
|
|
204
207
|
{icon && <span className={css(styles.labelIcon)}>{icon}</span>}
|
|
@@ -58,13 +58,15 @@ export interface MenuItemProps extends Omit<React.HTMLProps<HTMLLIElement>, 'onC
|
|
|
58
58
|
isOnPath?: boolean;
|
|
59
59
|
/** Accessibility label */
|
|
60
60
|
'aria-label'?: string;
|
|
61
|
+
/** @hide Forwarded ref */
|
|
62
|
+
innerRef?: React.Ref<HTMLAnchorElement | HTMLButtonElement>;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
const FlyoutContext = React.createContext({
|
|
64
66
|
direction: 'right' as 'left' | 'right'
|
|
65
67
|
});
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
const MenuItemBase: React.FunctionComponent<MenuItemProps> = ({
|
|
68
70
|
children,
|
|
69
71
|
className,
|
|
70
72
|
itemId = null,
|
|
@@ -86,6 +88,7 @@ export const MenuItem: React.FunctionComponent<MenuItemProps> = ({
|
|
|
86
88
|
onShowFlyout,
|
|
87
89
|
drilldownMenu,
|
|
88
90
|
isOnPath,
|
|
91
|
+
innerRef,
|
|
89
92
|
...props
|
|
90
93
|
}: MenuItemProps) => {
|
|
91
94
|
const {
|
|
@@ -293,6 +296,7 @@ export const MenuItem: React.FunctionComponent<MenuItemProps> = ({
|
|
|
293
296
|
aria-current={getAriaCurrent()}
|
|
294
297
|
disabled={isDisabled}
|
|
295
298
|
role="menuitem"
|
|
299
|
+
ref={innerRef}
|
|
296
300
|
onClick={(event: any) => {
|
|
297
301
|
onItemSelect(event, onSelect);
|
|
298
302
|
_drill && _drill();
|
|
@@ -352,4 +356,8 @@ export const MenuItem: React.FunctionComponent<MenuItemProps> = ({
|
|
|
352
356
|
);
|
|
353
357
|
};
|
|
354
358
|
|
|
359
|
+
export const MenuItem = React.forwardRef((props: MenuItemProps, ref: React.Ref<any>) => (
|
|
360
|
+
<MenuItemBase {...props} innerRef={ref} />
|
|
361
|
+
));
|
|
362
|
+
|
|
355
363
|
MenuItem.displayName = 'MenuItem';
|
|
@@ -1246,39 +1246,41 @@ class ViewMoreMenu extends React.Component {
|
|
|
1246
1246
|
isLoading: false,
|
|
1247
1247
|
numOptions: 3
|
|
1248
1248
|
};
|
|
1249
|
+
this.activeItemRef = React.createRef();
|
|
1250
|
+
this.viewMoreRef = React.createRef();
|
|
1249
1251
|
|
|
1250
1252
|
this.menuOptions = [
|
|
1251
|
-
<MenuItem key={0} itemId={0}>
|
|
1253
|
+
<MenuItem key={0} itemId={'view-more-0'}>
|
|
1252
1254
|
Action
|
|
1253
1255
|
</MenuItem>,
|
|
1254
1256
|
<MenuItem
|
|
1255
|
-
key={
|
|
1256
|
-
itemId={1}
|
|
1257
|
+
key={1}
|
|
1258
|
+
itemId={'view-more-1'}
|
|
1257
1259
|
to="#default-link2"
|
|
1258
1260
|
// just for demo so that navigation is not triggered
|
|
1259
1261
|
onClick={event => event.preventDefault()}
|
|
1260
1262
|
>
|
|
1261
1263
|
Link
|
|
1262
1264
|
</MenuItem>,
|
|
1263
|
-
<MenuItem key={
|
|
1265
|
+
<MenuItem key={2} itemId="view-more-2" isDisabled>
|
|
1264
1266
|
Disabled action
|
|
1265
1267
|
</MenuItem>,
|
|
1266
|
-
<MenuItem key={
|
|
1268
|
+
<MenuItem key={3} itemId="view-more-3" isDisabled to="#default-link4">
|
|
1267
1269
|
Disabled link
|
|
1268
1270
|
</MenuItem>,
|
|
1269
|
-
<MenuItem key={
|
|
1271
|
+
<MenuItem key={4} itemId="view-more-4" ref={this.activeItemRef}>
|
|
1270
1272
|
Action 2
|
|
1271
1273
|
</MenuItem>,
|
|
1272
|
-
<MenuItem key={
|
|
1274
|
+
<MenuItem key={5} itemId="view-more-5">
|
|
1273
1275
|
Action 3
|
|
1274
1276
|
</MenuItem>,
|
|
1275
|
-
<MenuItem key={
|
|
1277
|
+
<MenuItem key={6} itemId="view-more-6">
|
|
1276
1278
|
Action 4
|
|
1277
1279
|
</MenuItem>,
|
|
1278
|
-
<MenuItem key={
|
|
1280
|
+
<MenuItem key={7} itemId="view-more-7">
|
|
1279
1281
|
Action 5
|
|
1280
1282
|
</MenuItem>,
|
|
1281
|
-
<MenuItem key={
|
|
1283
|
+
<MenuItem key={8} itemId="view-more-8">
|
|
1282
1284
|
Final option
|
|
1283
1285
|
</MenuItem>
|
|
1284
1286
|
];
|
|
@@ -1290,25 +1292,38 @@ class ViewMoreMenu extends React.Component {
|
|
|
1290
1292
|
});
|
|
1291
1293
|
};
|
|
1292
1294
|
|
|
1293
|
-
this.simulateNetworkCall =
|
|
1294
|
-
setTimeout(
|
|
1295
|
+
this.simulateNetworkCall = networkCallback => {
|
|
1296
|
+
setTimeout(networkCallback, 2000);
|
|
1295
1297
|
};
|
|
1296
1298
|
|
|
1297
|
-
this.
|
|
1298
|
-
let
|
|
1299
|
-
|
|
1300
|
-
|
|
1299
|
+
this.getNextValidItem = (startingIndex, maxLength) => {
|
|
1300
|
+
let validItem;
|
|
1301
|
+
for (let i = startingIndex; i < maxLength; i++) {
|
|
1302
|
+
if (this.menuOptions[i].props.isDisabled) {
|
|
1303
|
+
continue;
|
|
1304
|
+
} else {
|
|
1305
|
+
validItem = this.menuOptions[i];
|
|
1306
|
+
break;
|
|
1307
|
+
}
|
|
1301
1308
|
}
|
|
1302
|
-
return
|
|
1309
|
+
return validItem;
|
|
1310
|
+
};
|
|
1311
|
+
|
|
1312
|
+
this.loadMoreOptions = stateCallback => {
|
|
1313
|
+
const newLength =
|
|
1314
|
+
this.state.numOptions + 3 <= this.menuOptions.length ? this.state.numOptions + 3 : this.menuOptions.length;
|
|
1315
|
+
const prevPosition = this.state.numOptions;
|
|
1316
|
+
const nextValidItem = this.getNextValidItem(prevPosition, newLength);
|
|
1317
|
+
|
|
1318
|
+
this.setState({ numOptions: newLength, isLoading: false, activeItem: nextValidItem.props.itemId }, stateCallback);
|
|
1303
1319
|
};
|
|
1304
1320
|
|
|
1305
|
-
this.onViewMoreClick =
|
|
1321
|
+
this.onViewMoreClick = event => {
|
|
1306
1322
|
this.setState({ isLoading: true });
|
|
1307
1323
|
this.simulateNetworkCall(() => {
|
|
1308
|
-
|
|
1309
|
-
this.
|
|
1310
|
-
|
|
1311
|
-
this.setState({ numOptions: newLength, isLoading: false });
|
|
1324
|
+
this.loadMoreOptions(() => {
|
|
1325
|
+
this.activeItemRef.current.focus();
|
|
1326
|
+
});
|
|
1312
1327
|
});
|
|
1313
1328
|
};
|
|
1314
1329
|
|
|
@@ -1321,15 +1336,14 @@ class ViewMoreMenu extends React.Component {
|
|
|
1321
1336
|
|
|
1322
1337
|
this.setState({ isLoading: true });
|
|
1323
1338
|
this.simulateNetworkCall(() => {
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
this.
|
|
1331
|
-
|
|
1332
|
-
nextFocus.focus();
|
|
1339
|
+
this.loadMoreOptions(() => {
|
|
1340
|
+
if (this.viewMoreRef.current) {
|
|
1341
|
+
this.viewMoreRef.current.tabIndex = -1;
|
|
1342
|
+
}
|
|
1343
|
+
const firstMenuItem = this.activeItemRef.current.closest('ul').firstChild;
|
|
1344
|
+
firstMenuItem.querySelector('button, a').tabIndex = -1;
|
|
1345
|
+
this.activeItemRef.current.tabIndex = 0;
|
|
1346
|
+
this.activeItemRef.current.focus();
|
|
1333
1347
|
});
|
|
1334
1348
|
});
|
|
1335
1349
|
};
|
|
@@ -1341,7 +1355,17 @@ class ViewMoreMenu extends React.Component {
|
|
|
1341
1355
|
<Menu activeItemId={activeItem} onSelect={this.onSelect}>
|
|
1342
1356
|
<MenuContent>
|
|
1343
1357
|
<MenuList>
|
|
1344
|
-
{this.menuOptions.slice(0, numOptions)
|
|
1358
|
+
{this.menuOptions.slice(0, numOptions).map(option => {
|
|
1359
|
+
const props = option.props;
|
|
1360
|
+
|
|
1361
|
+
return (
|
|
1362
|
+
<MenuItem
|
|
1363
|
+
key={option.key}
|
|
1364
|
+
{...props}
|
|
1365
|
+
ref={props.itemId === this.state.activeItem ? this.activeItemRef : null}
|
|
1366
|
+
/>
|
|
1367
|
+
);
|
|
1368
|
+
})}
|
|
1345
1369
|
{numOptions !== this.menuOptions.length && (
|
|
1346
1370
|
<MenuItem
|
|
1347
1371
|
{...(!isLoading && { isLoadButton: true })}
|
|
@@ -1349,6 +1373,7 @@ class ViewMoreMenu extends React.Component {
|
|
|
1349
1373
|
onKeyDown={this.onViewMoreKeyDown}
|
|
1350
1374
|
onClick={this.onViewMoreClick}
|
|
1351
1375
|
itemId="loader"
|
|
1376
|
+
ref={this.viewMoreRef}
|
|
1352
1377
|
>
|
|
1353
1378
|
{isLoading ? <Spinner size="lg" /> : 'View more'}
|
|
1354
1379
|
</MenuItem>
|
|
@@ -5,7 +5,7 @@ import { getUniqueId } from '../../helpers/util';
|
|
|
5
5
|
|
|
6
6
|
export interface NavGroupProps extends React.HTMLProps<HTMLDivElement> {
|
|
7
7
|
/** Title shown for the group */
|
|
8
|
-
title
|
|
8
|
+
title?: string;
|
|
9
9
|
/** Anything that can be rendered inside of the group */
|
|
10
10
|
children?: React.ReactNode;
|
|
11
11
|
/** Additional classes added to the container */
|
|
@@ -20,12 +20,23 @@ export const NavGroup: React.FunctionComponent<NavGroupProps> = ({
|
|
|
20
20
|
className = '',
|
|
21
21
|
id = getUniqueId(),
|
|
22
22
|
...props
|
|
23
|
-
}: NavGroupProps) =>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
}: NavGroupProps) => {
|
|
24
|
+
if (!title && !props['aria-label']) {
|
|
25
|
+
// eslint-disable-next-line no-console
|
|
26
|
+
console.warn("For accessibility reasons an aria-label should be specified on nav groups if a title isn't");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const labelledBy = title ? id : undefined;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<section className={css(styles.navSection, className)} aria-labelledby={labelledBy} {...props}>
|
|
33
|
+
{title && (
|
|
34
|
+
<h2 className={css(styles.navSectionTitle)} id={id}>
|
|
35
|
+
{title}
|
|
36
|
+
</h2>
|
|
37
|
+
)}
|
|
38
|
+
<ul className={css(styles.navList, className)}>{children}</ul>
|
|
39
|
+
</section>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
31
42
|
NavGroup.displayName = 'NavGroup';
|
|
@@ -55,6 +55,8 @@ class NavDefaultList extends React.Component {
|
|
|
55
55
|
|
|
56
56
|
### Grouped
|
|
57
57
|
|
|
58
|
+
Note: to keep nav groups accessible an `aria-label` should be supplied if the `title` prop is not passed.
|
|
59
|
+
|
|
58
60
|
```js
|
|
59
61
|
import React from 'react';
|
|
60
62
|
import { Nav, NavExpandable, NavItem, NavItemSeparator, NavList, NavGroup } from '@patternfly/react-core';
|
|
@@ -13,7 +13,9 @@ export interface ToolbarProps extends React.HTMLProps<HTMLDivElement>, OUIAProps
|
|
|
13
13
|
clearAllFilters?: () => void;
|
|
14
14
|
/** Text to display in the clear all filters button */
|
|
15
15
|
clearFiltersButtonText?: string;
|
|
16
|
-
/**
|
|
16
|
+
/** Custom content appended to the filter generated chip group. To maintain spacing and styling, each node should be wrapped in a ToolbarItem or ToolbarGroup. This property will remove the default "Clear all filters" button. */
|
|
17
|
+
customChipGroupContent?: React.ReactNode;
|
|
18
|
+
/** The breakpoint at which the listed filters in chip groups are collapsed down to a summary */
|
|
17
19
|
collapseListedFiltersBreakpoint?: 'all' | 'md' | 'lg' | 'xl' | '2xl';
|
|
18
20
|
/** Flag indicating if a data toolbar toggle group's expandable content is expanded */
|
|
19
21
|
isExpanded?: boolean;
|
|
@@ -129,6 +131,7 @@ export class Toolbar extends React.Component<ToolbarProps, ToolbarState> {
|
|
|
129
131
|
isSticky,
|
|
130
132
|
ouiaId,
|
|
131
133
|
numberOfFiltersText,
|
|
134
|
+
customChipGroupContent,
|
|
132
135
|
...props
|
|
133
136
|
} = this.props;
|
|
134
137
|
|
|
@@ -166,7 +169,8 @@ export class Toolbar extends React.Component<ToolbarProps, ToolbarState> {
|
|
|
166
169
|
clearAllFilters,
|
|
167
170
|
clearFiltersButtonText,
|
|
168
171
|
showClearFiltersButton,
|
|
169
|
-
toolbarId: randomId
|
|
172
|
+
toolbarId: randomId,
|
|
173
|
+
customChipGroupContent
|
|
170
174
|
}}
|
|
171
175
|
>
|
|
172
176
|
{children}
|
|
@@ -179,6 +183,7 @@ export class Toolbar extends React.Component<ToolbarProps, ToolbarState> {
|
|
|
179
183
|
numberOfFilters={numberOfFilters}
|
|
180
184
|
numberOfFiltersText={numberOfFiltersText}
|
|
181
185
|
collapseListedFiltersBreakpoint={collapseListedFiltersBreakpoint}
|
|
186
|
+
customChipGroupContent={customChipGroupContent}
|
|
182
187
|
/>
|
|
183
188
|
</ToolbarContext.Provider>
|
|
184
189
|
</div>
|
|
@@ -29,6 +29,8 @@ export interface ToolbarChipGroupContentProps extends React.HTMLProps<HTMLDivEle
|
|
|
29
29
|
numberOfFiltersText?: (numberOfFilters: number) => string;
|
|
30
30
|
/** The breakpoint at which the listed filters in chip groups are collapsed down to a summary */
|
|
31
31
|
collapseListedFiltersBreakpoint?: 'all' | 'md' | 'lg' | 'xl' | '2xl';
|
|
32
|
+
/** Custom additional content appended to the generated chips. To maintain spacing and styling, each node should be a ToolbarItem or ToolbarGroup. This property will remove the built in "Clear all filters" button. */
|
|
33
|
+
customChipGroupContent?: React.ReactNode;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
export class ToolbarChipGroupContent extends React.Component<ToolbarChipGroupContentProps> {
|
|
@@ -50,6 +52,7 @@ export class ToolbarChipGroupContent extends React.Component<ToolbarChipGroupCon
|
|
|
50
52
|
collapseListedFiltersBreakpoint,
|
|
51
53
|
numberOfFilters,
|
|
52
54
|
numberOfFiltersText,
|
|
55
|
+
customChipGroupContent,
|
|
53
56
|
...props
|
|
54
57
|
} = this.props;
|
|
55
58
|
|
|
@@ -86,13 +89,14 @@ export class ToolbarChipGroupContent extends React.Component<ToolbarChipGroupCon
|
|
|
86
89
|
<ToolbarItem>{numberOfFiltersText(numberOfFilters)}</ToolbarItem>
|
|
87
90
|
</ToolbarGroup>
|
|
88
91
|
)}
|
|
89
|
-
{showClearFiltersButton && !isExpanded && (
|
|
92
|
+
{showClearFiltersButton && !isExpanded && !customChipGroupContent && (
|
|
90
93
|
<ToolbarItem>
|
|
91
94
|
<Button variant="link" onClick={clearChipGroups} isInline>
|
|
92
95
|
{clearFiltersButtonText}
|
|
93
96
|
</Button>
|
|
94
97
|
</ToolbarItem>
|
|
95
98
|
)}
|
|
99
|
+
{customChipGroupContent && customChipGroupContent}
|
|
96
100
|
</div>
|
|
97
101
|
);
|
|
98
102
|
}
|
|
@@ -46,7 +46,7 @@ export class ToolbarExpandableContent extends React.Component<ToolbarExpandableC
|
|
|
46
46
|
showClearFiltersButton,
|
|
47
47
|
...props
|
|
48
48
|
} = this.props;
|
|
49
|
-
const { numberOfFilters } = this.context;
|
|
49
|
+
const { numberOfFilters, customChipGroupContent } = this.context;
|
|
50
50
|
|
|
51
51
|
const clearChipGroups = () => {
|
|
52
52
|
clearAllFilters();
|
|
@@ -58,13 +58,14 @@ export class ToolbarExpandableContent extends React.Component<ToolbarExpandableC
|
|
|
58
58
|
{numberOfFilters > 0 && (
|
|
59
59
|
<ToolbarGroup className={styles.modifiers.chipContainer}>
|
|
60
60
|
<ToolbarGroup ref={chipContainerRef} />
|
|
61
|
-
{showClearFiltersButton && (
|
|
61
|
+
{showClearFiltersButton && !customChipGroupContent && (
|
|
62
62
|
<ToolbarItem>
|
|
63
63
|
<Button variant="link" onClick={clearChipGroups} isInline>
|
|
64
64
|
{clearFiltersButtonText}
|
|
65
65
|
</Button>
|
|
66
66
|
</ToolbarItem>
|
|
67
67
|
)}
|
|
68
|
+
{customChipGroupContent && customChipGroupContent}
|
|
68
69
|
</ToolbarGroup>
|
|
69
70
|
)}
|
|
70
71
|
</div>
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import { shallow } from 'enzyme';
|
|
4
4
|
import { ToolbarToggleGroup } from '../ToolbarToggleGroup';
|
|
5
5
|
import { Toolbar } from '../Toolbar';
|
|
6
6
|
import { ToolbarItem } from '../ToolbarItem';
|
|
7
7
|
import { ToolbarContent } from '../ToolbarContent';
|
|
8
|
+
import { ToolbarFilter } from '../ToolbarFilter';
|
|
9
|
+
import { ToolbarGroup } from '../ToolbarGroup';
|
|
10
|
+
import { Select, SelectVariant, SelectOption } from '../../Select';
|
|
11
|
+
import { Button } from '../../Button';
|
|
8
12
|
|
|
9
13
|
describe('ToolbarToggleGroup', () => {
|
|
10
14
|
it('should warn on bad props', () => {
|
|
@@ -59,6 +63,72 @@ describe('Toolbar', () => {
|
|
|
59
63
|
);
|
|
60
64
|
expect(view.container).toMatchSnapshot();
|
|
61
65
|
});
|
|
66
|
+
|
|
67
|
+
it('should render with custom chip content', () => {
|
|
68
|
+
const statusMenuItems = [
|
|
69
|
+
<SelectOption key="statusNew" value="New" />,
|
|
70
|
+
<SelectOption key="statusPending" value="Pending" />,
|
|
71
|
+
<SelectOption key="statusRunning" value="Running" />,
|
|
72
|
+
<SelectOption key="statusCancelled" value="Cancelled" />
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
const items = (
|
|
76
|
+
<React.Fragment>
|
|
77
|
+
<ToolbarToggleGroup toggleIcon={<React.Fragment />} breakpoint="xl">
|
|
78
|
+
<ToolbarGroup variant="filter-group">
|
|
79
|
+
<ToolbarFilter
|
|
80
|
+
chips={['New', 'Pending']}
|
|
81
|
+
deleteChip={(category, chip) => {}}
|
|
82
|
+
deleteChipGroup={category => {}}
|
|
83
|
+
categoryName="Status"
|
|
84
|
+
>
|
|
85
|
+
<Select
|
|
86
|
+
variant={SelectVariant.checkbox}
|
|
87
|
+
aria-label="Status"
|
|
88
|
+
onToggle={(isExpanded: boolean) => {}}
|
|
89
|
+
onSelect={(event, selection) => {}}
|
|
90
|
+
selections={['New', 'Pending']}
|
|
91
|
+
isOpen={true}
|
|
92
|
+
placeholderText="Status"
|
|
93
|
+
>
|
|
94
|
+
{statusMenuItems}
|
|
95
|
+
</Select>
|
|
96
|
+
</ToolbarFilter>
|
|
97
|
+
</ToolbarGroup>
|
|
98
|
+
</ToolbarToggleGroup>
|
|
99
|
+
</React.Fragment>
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const customChipGroupContent = (
|
|
103
|
+
<React.Fragment>
|
|
104
|
+
<ToolbarItem>
|
|
105
|
+
<Button variant="link" onClick={() => {}} isInline>
|
|
106
|
+
Save filters
|
|
107
|
+
</Button>
|
|
108
|
+
</ToolbarItem>
|
|
109
|
+
<ToolbarItem>
|
|
110
|
+
<Button variant="link" onClick={() => {}} isInline>
|
|
111
|
+
Clear all filters
|
|
112
|
+
</Button>
|
|
113
|
+
</ToolbarItem>
|
|
114
|
+
</React.Fragment>
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const view = render(
|
|
118
|
+
<Toolbar
|
|
119
|
+
id="toolbar-with-filter"
|
|
120
|
+
className="pf-m-toggle-group-container"
|
|
121
|
+
collapseListedFiltersBreakpoint="xl"
|
|
122
|
+
customChipGroupContent={customChipGroupContent}
|
|
123
|
+
>
|
|
124
|
+
<ToolbarContent>{items}</ToolbarContent>
|
|
125
|
+
</Toolbar>
|
|
126
|
+
);
|
|
127
|
+
// Expecting 2 matches for text because the buttons also exist in hidden expandable content for mobile view
|
|
128
|
+
expect(screen.getAllByRole('button', { name: 'Save filters' }).length).toBe(2);
|
|
129
|
+
expect(screen.getAllByRole('button', { name: 'Clear all filters' }).length).toBe(2);
|
|
130
|
+
expect(view.container).toMatchSnapshot();
|
|
131
|
+
});
|
|
62
132
|
});
|
|
63
133
|
|
|
64
134
|
describe('ToolbarItem', () => {
|