@patternfly/react-core 4.175.1 → 4.175.5
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 +38 -0
- package/dist/esm/components/Card/Card.d.ts +3 -3
- package/dist/esm/components/Card/Card.d.ts.map +1 -1
- package/dist/esm/components/FileUpload/FileUpload.d.ts +3 -3
- package/dist/esm/components/FileUpload/FileUpload.d.ts.map +1 -1
- package/dist/esm/components/FileUpload/FileUpload.js +5 -2
- package/dist/esm/components/FileUpload/FileUpload.js.map +1 -1
- package/dist/esm/components/Menu/Menu.d.ts +2 -0
- package/dist/esm/components/Menu/Menu.d.ts.map +1 -1
- package/dist/esm/components/Menu/Menu.js +4 -5
- package/dist/esm/components/Menu/Menu.js.map +1 -1
- package/dist/esm/components/Menu/MenuContent.js +1 -4
- package/dist/esm/components/Menu/MenuContent.js.map +1 -1
- package/dist/esm/components/Menu/MenuContext.d.ts +0 -1
- package/dist/esm/components/Menu/MenuContext.d.ts.map +1 -1
- package/dist/esm/components/Menu/MenuContext.js +1 -2
- package/dist/esm/components/Menu/MenuContext.js.map +1 -1
- package/dist/esm/components/Nav/NavItem.d.ts +1 -1
- package/dist/esm/components/Nav/NavItem.d.ts.map +1 -1
- package/dist/esm/components/Nav/NavItem.js +41 -31
- package/dist/esm/components/Nav/NavItem.js.map +1 -1
- package/dist/js/components/Card/Card.d.ts +3 -3
- package/dist/js/components/Card/Card.d.ts.map +1 -1
- package/dist/js/components/FileUpload/FileUpload.d.ts +3 -3
- package/dist/js/components/FileUpload/FileUpload.d.ts.map +1 -1
- package/dist/js/components/FileUpload/FileUpload.js +5 -2
- package/dist/js/components/FileUpload/FileUpload.js.map +1 -1
- package/dist/js/components/Menu/Menu.d.ts +2 -0
- package/dist/js/components/Menu/Menu.d.ts.map +1 -1
- package/dist/js/components/Menu/Menu.js +4 -5
- package/dist/js/components/Menu/Menu.js.map +1 -1
- package/dist/js/components/Menu/MenuContent.js +1 -4
- package/dist/js/components/Menu/MenuContent.js.map +1 -1
- package/dist/js/components/Menu/MenuContext.d.ts +0 -1
- package/dist/js/components/Menu/MenuContext.d.ts.map +1 -1
- package/dist/js/components/Menu/MenuContext.js +1 -2
- package/dist/js/components/Menu/MenuContext.js.map +1 -1
- package/dist/js/components/Nav/NavItem.d.ts +1 -1
- package/dist/js/components/Nav/NavItem.d.ts.map +1 -1
- package/dist/js/components/Nav/NavItem.js +41 -31
- package/dist/js/components/Nav/NavItem.js.map +1 -1
- package/dist/umd/react-core.js +1346 -1580
- package/dist/umd/react-core.min.js +4 -3
- package/package.json +6 -6
- package/src/components/Card/Card.tsx +3 -3
- package/src/components/FileUpload/FileUpload.tsx +18 -14
- package/src/components/FileUpload/__tests__/__snapshots__/FileUpload.test.tsx.snap +7 -3
- package/src/components/FileUpload/examples/FileUpload.md +3 -2
- package/src/components/Menu/Menu.tsx +5 -2
- package/src/components/Menu/MenuContent.tsx +3 -3
- package/src/components/Menu/MenuContext.ts +1 -3
- package/src/components/Menu/__tests__/Menu.test.tsx +11 -0
- package/src/components/Menu/__tests__/__snapshots__/Menu.test.tsx.snap +11 -0
- package/src/components/Nav/NavItem.tsx +78 -48
- package/src/components/Nav/__tests__/Generated/NavItem.test.tsx +1 -1
- package/src/components/Nav/__tests__/Generated/__snapshots__/NavItem.test.tsx.snap +13 -11
- package/src/components/Nav/examples/Nav.md +4 -3
- package/src/demos/Nav.md +105 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.175.
|
|
3
|
+
"version": "4.175.5",
|
|
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,11 +34,11 @@
|
|
|
34
34
|
"generate": "node scripts/copyStyles.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@patternfly/react-icons": "^4.26.
|
|
38
|
-
"@patternfly/react-styles": "^4.25.
|
|
39
|
-
"@patternfly/react-tokens": "^4.27.
|
|
37
|
+
"@patternfly/react-icons": "^4.26.5",
|
|
38
|
+
"@patternfly/react-styles": "^4.25.5",
|
|
39
|
+
"@patternfly/react-tokens": "^4.27.5",
|
|
40
40
|
"focus-trap": "6.2.2",
|
|
41
|
-
"react-dropzone": "
|
|
41
|
+
"react-dropzone": "9.0.0",
|
|
42
42
|
"tippy.js": "5.1.2",
|
|
43
43
|
"tslib": "^2.0.0"
|
|
44
44
|
},
|
|
@@ -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": "4839fc921658bb20596bd0851c71263e30257b80"
|
|
64
64
|
}
|
|
@@ -14,7 +14,7 @@ export interface CardProps extends React.HTMLProps<HTMLElement>, OUIAProps {
|
|
|
14
14
|
component?: keyof JSX.IntrinsicElements;
|
|
15
15
|
/** Modifies the card to include hover styles on :hover */
|
|
16
16
|
isHoverable?: boolean;
|
|
17
|
-
/** Modifies the card to include hoverable-raised styles on :hover, this styling is included by default with isSelectableRaised */
|
|
17
|
+
/** @beta Modifies the card to include hoverable-raised styles on :hover, this styling is included by default with isSelectableRaised */
|
|
18
18
|
isHoverableRaised?: boolean;
|
|
19
19
|
/** Modifies the card to include compact styling. Should not be used with isLarge. */
|
|
20
20
|
isCompact?: boolean;
|
|
@@ -22,9 +22,9 @@ export interface CardProps extends React.HTMLProps<HTMLElement>, OUIAProps {
|
|
|
22
22
|
isSelectable?: boolean;
|
|
23
23
|
/** Modifies the card to include selected styling */
|
|
24
24
|
isSelected?: boolean;
|
|
25
|
-
/** Modifies the card to include selectable-raised styling and hoverable-raised styling */
|
|
25
|
+
/** @beta Modifies the card to include selectable-raised styling and hoverable-raised styling */
|
|
26
26
|
isSelectableRaised?: boolean;
|
|
27
|
-
/** Modifies the card to include selected-raised styling */
|
|
27
|
+
/** @beta Modifies the card to include selected-raised styling */
|
|
28
28
|
isSelectedRaised?: boolean;
|
|
29
29
|
/** Modifies the card to include flat styling */
|
|
30
30
|
isFlat?: boolean;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import Dropzone, { DropzoneProps,
|
|
2
|
+
import Dropzone, { DropzoneProps, DropzoneInputProps, DropFileEventHandler } from 'react-dropzone';
|
|
3
3
|
import { FileUploadField, FileUploadFieldProps } from './FileUploadField';
|
|
4
4
|
import { readFile, fileReaderType } from '../../helpers/fileUtils';
|
|
5
5
|
import { fromEvent } from 'file-selector';
|
|
6
|
+
|
|
7
|
+
interface DropzoneInputPropsWithRef extends DropzoneInputProps {
|
|
8
|
+
ref: React.RefCallback<HTMLInputElement>; // Working around an issue in react-dropzone 9.0.0's types. Should not be necessary in later versions.
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
export interface FileUploadProps
|
|
7
12
|
extends Omit<
|
|
8
13
|
FileUploadFieldProps,
|
|
@@ -26,11 +31,9 @@ export interface FileUploadProps
|
|
|
26
31
|
| React.MouseEvent<HTMLButtonElement, MouseEvent> // Clear button was clicked
|
|
27
32
|
| React.DragEvent<HTMLElement> // User dragged/dropped a file
|
|
28
33
|
| React.ChangeEvent<HTMLElement> // User typed in the TextArea
|
|
29
|
-
| DragEvent
|
|
30
|
-
| Event
|
|
31
34
|
) => void;
|
|
32
35
|
/** Change event emitted from the hidden \<input type="file" \> field associated with the component */
|
|
33
|
-
onFileInputChange?: (event: React.ChangeEvent<HTMLInputElement> |
|
|
36
|
+
onFileInputChange?: (event: React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLElement>, file: File) => void;
|
|
34
37
|
/** Callback for clicking on the FileUploadField text area. By default, prevents a click in the text area from opening file dialog. */
|
|
35
38
|
onClick?: (event: React.MouseEvent) => void;
|
|
36
39
|
/** Additional classes added to the FileUpload container element. */
|
|
@@ -104,7 +107,7 @@ export const FileUpload: React.FunctionComponent<FileUploadProps> = ({
|
|
|
104
107
|
dropzoneProps = {},
|
|
105
108
|
...props
|
|
106
109
|
}: FileUploadProps) => {
|
|
107
|
-
const onDropAccepted = (acceptedFiles
|
|
110
|
+
const onDropAccepted: DropFileEventHandler = (acceptedFiles, event) => {
|
|
108
111
|
if (acceptedFiles.length > 0) {
|
|
109
112
|
const fileHandle = acceptedFiles[0];
|
|
110
113
|
if (event.type === 'drop') {
|
|
@@ -132,7 +135,7 @@ export const FileUpload: React.FunctionComponent<FileUploadProps> = ({
|
|
|
132
135
|
dropzoneProps.onDropAccepted && dropzoneProps.onDropAccepted(acceptedFiles, event);
|
|
133
136
|
};
|
|
134
137
|
|
|
135
|
-
const onDropRejected = (rejectedFiles
|
|
138
|
+
const onDropRejected: DropFileEventHandler = (rejectedFiles, event) => {
|
|
136
139
|
if (rejectedFiles.length > 0) {
|
|
137
140
|
onChange('', rejectedFiles[0].name, event);
|
|
138
141
|
}
|
|
@@ -151,13 +154,7 @@ export const FileUpload: React.FunctionComponent<FileUploadProps> = ({
|
|
|
151
154
|
};
|
|
152
155
|
|
|
153
156
|
return (
|
|
154
|
-
<Dropzone
|
|
155
|
-
multiple={false}
|
|
156
|
-
{...dropzoneProps}
|
|
157
|
-
onDropAccepted={onDropAccepted}
|
|
158
|
-
onDropRejected={onDropRejected}
|
|
159
|
-
noClick={true}
|
|
160
|
-
>
|
|
157
|
+
<Dropzone multiple={false} {...dropzoneProps} onDropAccepted={onDropAccepted} onDropRejected={onDropRejected}>
|
|
161
158
|
{({ getRootProps, getInputProps, isDragActive, open }) => {
|
|
162
159
|
const oldInputProps = getInputProps();
|
|
163
160
|
const inputProps: DropzoneInputProps = {
|
|
@@ -190,7 +187,14 @@ export const FileUpload: React.FunctionComponent<FileUploadProps> = ({
|
|
|
190
187
|
onTextAreaClick={onClick}
|
|
191
188
|
onTextChange={onTextChange}
|
|
192
189
|
>
|
|
193
|
-
<input
|
|
190
|
+
<input
|
|
191
|
+
/* hidden, necessary for react-dropzone */
|
|
192
|
+
{...inputProps}
|
|
193
|
+
ref={input => {
|
|
194
|
+
fileInputRef.current = input;
|
|
195
|
+
(inputProps as DropzoneInputPropsWithRef).ref(input);
|
|
196
|
+
}}
|
|
197
|
+
/>
|
|
194
198
|
{children}
|
|
195
199
|
</FileUploadField>
|
|
196
200
|
);
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`simple fileupload 1`] = `
|
|
4
|
-
<
|
|
4
|
+
<t
|
|
5
|
+
disabled={false}
|
|
6
|
+
getDataTransferItems={[Function]}
|
|
7
|
+
maxSize={Infinity}
|
|
8
|
+
minSize={0}
|
|
5
9
|
multiple={false}
|
|
6
|
-
noClick={true}
|
|
7
10
|
onDropAccepted={[Function]}
|
|
8
11
|
onDropRejected={[Function]}
|
|
12
|
+
preventDropOnDocument={true}
|
|
9
13
|
>
|
|
10
14
|
<Component />
|
|
11
|
-
</
|
|
15
|
+
</t>
|
|
12
16
|
`;
|
|
@@ -27,7 +27,7 @@ class SimpleTextFileUpload extends React.Component {
|
|
|
27
27
|
super(props);
|
|
28
28
|
this.state = { value: '', filename: '', isLoading: false };
|
|
29
29
|
this.handleFileInputChange = (event, file) => this.setState({ filename: file.name });
|
|
30
|
-
this.
|
|
30
|
+
this.handleTextOrDataChange = value => this.setState({ value });
|
|
31
31
|
this.handleClear = event => this.setState({ filename: '', value: '' });
|
|
32
32
|
this.handleFileReadStarted = fileHandle => this.setState({ isLoading: true });
|
|
33
33
|
this.handleFileReadFinished = fileHandle => this.setState({ isLoading: false });
|
|
@@ -43,7 +43,8 @@ class SimpleTextFileUpload extends React.Component {
|
|
|
43
43
|
filename={filename}
|
|
44
44
|
filenamePlaceholder="Drag and drop a file or upload one"
|
|
45
45
|
onFileInputChange={this.handleFileInputChange}
|
|
46
|
-
onDataChange={this.
|
|
46
|
+
onDataChange={this.handleTextOrDataChange}
|
|
47
|
+
onTextChange={this.handleTextOrDataChange}
|
|
47
48
|
onReadStarted={this.handleFileReadStarted}
|
|
48
49
|
onReadFinished={this.handleFileReadFinished}
|
|
49
50
|
onClearClick={this.handleClear}
|
|
@@ -29,6 +29,8 @@ export interface MenuProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'r
|
|
|
29
29
|
'aria-label'?: string;
|
|
30
30
|
/** @beta Indicates if menu contains a flyout menu */
|
|
31
31
|
containsFlyout?: boolean;
|
|
32
|
+
/** @beta Indicating that the menu should have nav flyout styling */
|
|
33
|
+
isNavFlyout?: boolean;
|
|
32
34
|
/** @beta Indicates if menu contains a drilldown menu */
|
|
33
35
|
containsDrilldown?: boolean;
|
|
34
36
|
/** @beta Indicates if a menu is drilled into */
|
|
@@ -224,6 +226,7 @@ class MenuBase extends React.Component<MenuProps, MenuState> {
|
|
|
224
226
|
ouiaId,
|
|
225
227
|
ouiaSafe,
|
|
226
228
|
containsFlyout,
|
|
229
|
+
isNavFlyout,
|
|
227
230
|
containsDrilldown,
|
|
228
231
|
isMenuDrilledIn,
|
|
229
232
|
isPlain,
|
|
@@ -259,8 +262,7 @@ class MenuBase extends React.Component<MenuProps, MenuState> {
|
|
|
259
262
|
onGetMenuHeight,
|
|
260
263
|
flyoutRef: this.state.flyoutRef,
|
|
261
264
|
setFlyoutRef: flyoutRef => this.setState({ flyoutRef }),
|
|
262
|
-
disableHover: this.state.disableHover
|
|
263
|
-
isScrollable
|
|
265
|
+
disableHover: this.state.disableHover
|
|
264
266
|
}}
|
|
265
267
|
>
|
|
266
268
|
{isRootMenu && (
|
|
@@ -289,6 +291,7 @@ class MenuBase extends React.Component<MenuProps, MenuState> {
|
|
|
289
291
|
isPlain && styles.modifiers.plain,
|
|
290
292
|
isScrollable && styles.modifiers.scrollable,
|
|
291
293
|
containsFlyout && styles.modifiers.flyout,
|
|
294
|
+
isNavFlyout && styles.modifiers.nav,
|
|
292
295
|
containsDrilldown && styles.modifiers.drilldown,
|
|
293
296
|
_isMenuDrilledIn && styles.modifiers.drilledIn,
|
|
294
297
|
className
|
|
@@ -28,15 +28,15 @@ export const MenuContent = React.forwardRef((props: MenuContentProps, ref: React
|
|
|
28
28
|
};
|
|
29
29
|
return (
|
|
30
30
|
<MenuContext.Consumer>
|
|
31
|
-
{({ menuId, onGetMenuHeight
|
|
31
|
+
{({ menuId, onGetMenuHeight }) => (
|
|
32
32
|
<div
|
|
33
33
|
{...rest}
|
|
34
34
|
className={css(styles.menuContent, props.className)}
|
|
35
35
|
ref={el => refCallback(el, menuId, onGetMenuHeight)}
|
|
36
36
|
style={
|
|
37
37
|
{
|
|
38
|
-
'--pf-c-menu__content--Height': menuHeight
|
|
39
|
-
'--pf-c-menu__content--MaxHeight':
|
|
38
|
+
...(menuHeight && { '--pf-c-menu__content--Height': menuHeight }),
|
|
39
|
+
...(maxMenuHeight && { '--pf-c-menu__content--MaxHeight': maxMenuHeight })
|
|
40
40
|
} as React.CSSProperties
|
|
41
41
|
}
|
|
42
42
|
>
|
|
@@ -15,7 +15,6 @@ export const MenuContext = React.createContext<{
|
|
|
15
15
|
flyoutRef?: React.Ref<HTMLLIElement>;
|
|
16
16
|
setFlyoutRef?: (ref: React.Ref<HTMLLIElement>) => void;
|
|
17
17
|
disableHover?: boolean;
|
|
18
|
-
isScrollable?: boolean;
|
|
19
18
|
}>({
|
|
20
19
|
menuId: null,
|
|
21
20
|
parentMenu: null,
|
|
@@ -30,8 +29,7 @@ export const MenuContext = React.createContext<{
|
|
|
30
29
|
onGetMenuHeight: () => null,
|
|
31
30
|
flyoutRef: null,
|
|
32
31
|
setFlyoutRef: () => null,
|
|
33
|
-
disableHover: false
|
|
34
|
-
isScrollable: false
|
|
32
|
+
disableHover: false
|
|
35
33
|
});
|
|
36
34
|
|
|
37
35
|
export const MenuItemContext = React.createContext<{
|
|
@@ -31,4 +31,15 @@ describe('with isScrollable', () => {
|
|
|
31
31
|
);
|
|
32
32
|
expect(view.find('div.pf-m-scrollable')).toMatchSnapshot();
|
|
33
33
|
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('with isNavFlyout', () => {
|
|
37
|
+
test('should render Menu with nav flyout styles applied', () => {
|
|
38
|
+
const view = mount(
|
|
39
|
+
<Menu activeItemId={0} onSelect={jest.fn()} isNavFlyout>
|
|
40
|
+
content
|
|
41
|
+
</Menu>
|
|
42
|
+
);
|
|
43
|
+
expect(view.find('div.pf-m-nav')).toMatchSnapshot();
|
|
44
|
+
});
|
|
34
45
|
});
|
|
@@ -55,6 +55,17 @@ exports[`should render Menu successfully 1`] = `
|
|
|
55
55
|
</Menu>
|
|
56
56
|
`;
|
|
57
57
|
|
|
58
|
+
exports[`with isNavFlyout should render Menu with nav flyout styles applied 1`] = `
|
|
59
|
+
<div
|
|
60
|
+
className="pf-c-menu pf-m-nav"
|
|
61
|
+
data-ouia-component-id="OUIA-Generated-Menu-4"
|
|
62
|
+
data-ouia-component-type="PF4/Menu"
|
|
63
|
+
data-ouia-safe={true}
|
|
64
|
+
>
|
|
65
|
+
content
|
|
66
|
+
</div>
|
|
67
|
+
`;
|
|
68
|
+
|
|
58
69
|
exports[`with isPlain should render Menu with plain styles applied 1`] = `
|
|
59
70
|
<div
|
|
60
71
|
className="pf-c-menu pf-m-plain"
|
|
@@ -4,6 +4,7 @@ import { css } from '@patternfly/react-styles';
|
|
|
4
4
|
import { NavContext, NavSelectClickHandler } from './Nav';
|
|
5
5
|
import { PageSidebarContext } from '../Page/PageSidebar';
|
|
6
6
|
import { useOUIAProps, OUIAProps } from '../../helpers';
|
|
7
|
+
import { Popper } from '../../helpers/Popper/Popper';
|
|
7
8
|
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
|
|
8
9
|
|
|
9
10
|
export interface NavItemProps extends Omit<React.HTMLProps<HTMLAnchorElement>, 'onClick'>, OUIAProps {
|
|
@@ -28,7 +29,7 @@ export interface NavItemProps extends Omit<React.HTMLProps<HTMLAnchorElement>, '
|
|
|
28
29
|
/** Component used to render NavItems if React.isValidElement(children) is false */
|
|
29
30
|
component?: React.ReactNode;
|
|
30
31
|
/** Flyout of a nav item. This should be a Menu component. */
|
|
31
|
-
flyout?: React.
|
|
32
|
+
flyout?: React.ReactElement;
|
|
32
33
|
/** Callback when flyout is opened or closed */
|
|
33
34
|
onShowFlyout?: () => void;
|
|
34
35
|
}
|
|
@@ -53,8 +54,10 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
|
|
|
53
54
|
const { flyoutRef, setFlyoutRef } = React.useContext(NavContext);
|
|
54
55
|
const { isNavOpen } = React.useContext(PageSidebarContext);
|
|
55
56
|
const [flyoutTarget, setFlyoutTarget] = React.useState(null);
|
|
57
|
+
const [isHovered, setIsHovered] = React.useState(false);
|
|
56
58
|
const ref = React.useRef<HTMLLIElement>();
|
|
57
59
|
const flyoutVisible = ref === flyoutRef;
|
|
60
|
+
const popperRef = React.useRef<HTMLDivElement>();
|
|
58
61
|
const Component = component as any;
|
|
59
62
|
const hasFlyout = flyout !== undefined;
|
|
60
63
|
|
|
@@ -89,36 +92,11 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
|
|
|
89
92
|
}
|
|
90
93
|
};
|
|
91
94
|
|
|
92
|
-
|
|
93
|
-
if (hasFlyout) {
|
|
94
|
-
window.addEventListener('click', onFlyoutClick);
|
|
95
|
-
}
|
|
96
|
-
return () => {
|
|
97
|
-
if (hasFlyout) {
|
|
98
|
-
window.removeEventListener('click', onFlyoutClick);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}, []);
|
|
102
|
-
|
|
103
|
-
React.useEffect(() => {
|
|
104
|
-
if (flyoutTarget) {
|
|
105
|
-
if (flyoutVisible) {
|
|
106
|
-
const flyoutMenu = (flyoutTarget as HTMLElement).nextElementSibling;
|
|
107
|
-
const flyoutItems = Array.from(flyoutMenu.getElementsByTagName('UL')[0].children).filter(
|
|
108
|
-
el => !(el.classList.contains('pf-m-disabled') || el.classList.contains('pf-c-divider'))
|
|
109
|
-
);
|
|
110
|
-
(flyoutItems[0].firstChild as HTMLElement).focus();
|
|
111
|
-
} else {
|
|
112
|
-
flyoutTarget.focus();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}, [flyoutVisible, flyoutTarget]);
|
|
116
|
-
|
|
117
|
-
const handleFlyout = (event: React.KeyboardEvent) => {
|
|
95
|
+
const handleFlyout = (event: KeyboardEvent) => {
|
|
118
96
|
const key = event.key;
|
|
119
97
|
const target = event.target as HTMLElement;
|
|
120
98
|
|
|
121
|
-
if (!hasFlyout) {
|
|
99
|
+
if (!(popperRef?.current?.contains(target) || (hasFlyout && ref?.current?.contains(target)))) {
|
|
122
100
|
return;
|
|
123
101
|
}
|
|
124
102
|
|
|
@@ -140,6 +118,30 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
|
|
|
140
118
|
}
|
|
141
119
|
};
|
|
142
120
|
|
|
121
|
+
React.useEffect(() => {
|
|
122
|
+
if (hasFlyout) {
|
|
123
|
+
window.addEventListener('click', onFlyoutClick);
|
|
124
|
+
}
|
|
125
|
+
return () => {
|
|
126
|
+
if (hasFlyout) {
|
|
127
|
+
window.removeEventListener('click', onFlyoutClick);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}, []);
|
|
131
|
+
|
|
132
|
+
React.useEffect(() => {
|
|
133
|
+
if (flyoutTarget) {
|
|
134
|
+
if (flyoutVisible) {
|
|
135
|
+
const flyoutItems = Array.from(
|
|
136
|
+
(popperRef.current as HTMLElement).getElementsByTagName('UL')[0].children
|
|
137
|
+
).filter(el => !(el.classList.contains('pf-m-disabled') || el.classList.contains('pf-c-divider')));
|
|
138
|
+
(flyoutItems[0].firstChild as HTMLElement).focus();
|
|
139
|
+
} else {
|
|
140
|
+
flyoutTarget.focus();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}, [flyoutVisible, flyoutTarget]);
|
|
144
|
+
|
|
143
145
|
const flyoutButton = (
|
|
144
146
|
<span className={css(styles.navToggle)}>
|
|
145
147
|
<span className={css(styles.navToggleIcon)}>
|
|
@@ -154,7 +156,12 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
|
|
|
154
156
|
<Component
|
|
155
157
|
href={to}
|
|
156
158
|
onClick={(e: any) => context.onSelect(e, groupId, itemId, to, preventLinkDefault, onClick)}
|
|
157
|
-
className={css(
|
|
159
|
+
className={css(
|
|
160
|
+
styles.navLink,
|
|
161
|
+
isActive && styles.modifiers.current,
|
|
162
|
+
isHovered && styles.modifiers.hover,
|
|
163
|
+
className
|
|
164
|
+
)}
|
|
158
165
|
aria-current={isActive ? 'page' : null}
|
|
159
166
|
tabIndex={isNavOpen ? null : '-1'}
|
|
160
167
|
{...props}
|
|
@@ -185,25 +192,48 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
|
|
|
185
192
|
|
|
186
193
|
const ouiaProps = useOUIAProps(NavItem.displayName, ouiaId, ouiaSafe);
|
|
187
194
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
{flyoutVisible
|
|
206
|
-
|
|
195
|
+
const handleMouseEnter = () => {
|
|
196
|
+
setIsHovered(true);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const handleMouseLeave = () => {
|
|
200
|
+
setIsHovered(false);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const flyoutPopper = (
|
|
204
|
+
<Popper
|
|
205
|
+
reference={ref}
|
|
206
|
+
popper={
|
|
207
|
+
<div ref={popperRef} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}>
|
|
208
|
+
{flyout}
|
|
209
|
+
</div>
|
|
210
|
+
}
|
|
211
|
+
placement="right-start"
|
|
212
|
+
isVisible={flyoutVisible}
|
|
213
|
+
onDocumentKeyDown={handleFlyout}
|
|
214
|
+
/>
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
const navItem = (
|
|
218
|
+
<>
|
|
219
|
+
<li
|
|
220
|
+
onMouseOver={onMouseOver}
|
|
221
|
+
className={css(styles.navItem, hasFlyout && styles.modifiers.flyout, className)}
|
|
222
|
+
ref={ref}
|
|
223
|
+
{...ouiaProps}
|
|
224
|
+
>
|
|
225
|
+
<NavContext.Consumer>
|
|
226
|
+
{context =>
|
|
227
|
+
React.isValidElement(children)
|
|
228
|
+
? renderClonedChild(context, children as React.ReactElement)
|
|
229
|
+
: renderDefaultLink(context)
|
|
230
|
+
}
|
|
231
|
+
</NavContext.Consumer>
|
|
232
|
+
</li>
|
|
233
|
+
{flyout && flyoutPopper}
|
|
234
|
+
</>
|
|
207
235
|
);
|
|
236
|
+
|
|
237
|
+
return navItem;
|
|
208
238
|
};
|
|
209
239
|
NavItem.displayName = 'NavItem';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This test was generated
|
|
3
3
|
*/
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import { shallow } from 'enzyme';
|
|
5
|
+
import { shallow, mount } from 'enzyme';
|
|
6
6
|
import { NavItem } from '../../NavItem';
|
|
7
7
|
// any missing imports can usually be resolved by adding them here
|
|
8
8
|
import {} from '../..';
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`NavItem should match snapshot (auto-generated) 1`] = `
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
<
|
|
13
|
-
|
|
14
|
-
</
|
|
4
|
+
<Fragment>
|
|
5
|
+
<li
|
|
6
|
+
className="pf-c-nav__item ''"
|
|
7
|
+
data-ouia-component-id="OUIA-Generated-NavItem-1"
|
|
8
|
+
data-ouia-component-type="PF4/NavItem"
|
|
9
|
+
data-ouia-safe={true}
|
|
10
|
+
onMouseOver={[Function]}
|
|
11
|
+
>
|
|
12
|
+
<ContextConsumer>
|
|
13
|
+
<Component />
|
|
14
|
+
</ContextConsumer>
|
|
15
|
+
</li>
|
|
16
|
+
</Fragment>
|
|
15
17
|
`;
|
|
@@ -305,7 +305,7 @@ NavExpandableThirdLevelList = () => {
|
|
|
305
305
|
onSelect = result => {
|
|
306
306
|
setActiveGroup(result.groupId);
|
|
307
307
|
setActiveItem(result.itemId);
|
|
308
|
-
};
|
|
308
|
+
};
|
|
309
309
|
|
|
310
310
|
onToggle = result => {
|
|
311
311
|
// eslint-disable-next-line no-console
|
|
@@ -387,7 +387,7 @@ NavExpandableThirdLevelList = () => {
|
|
|
387
387
|
</NavList>
|
|
388
388
|
</Nav>
|
|
389
389
|
);
|
|
390
|
-
}
|
|
390
|
+
};
|
|
391
391
|
```
|
|
392
392
|
|
|
393
393
|
### Mixed
|
|
@@ -628,7 +628,7 @@ NavWithFlyout = () => {
|
|
|
628
628
|
|
|
629
629
|
const numFlyouts = 5;
|
|
630
630
|
const FlyoutMenu = ({ depth, children }) => (
|
|
631
|
-
<Menu key={depth} containsFlyout id={`menu-${depth}`} onSelect={onMenuSelect}>
|
|
631
|
+
<Menu key={depth} containsFlyout isNavFlyout id={`menu-${depth}`} onSelect={onMenuSelect}>
|
|
632
632
|
<MenuContent>
|
|
633
633
|
<MenuList>
|
|
634
634
|
<MenuItem flyoutMenu={children} itemId={`next-menu-${depth}`} to={`#menu-link-${depth}`}>
|
|
@@ -646,6 +646,7 @@ NavWithFlyout = () => {
|
|
|
646
646
|
</MenuContent>
|
|
647
647
|
</Menu>
|
|
648
648
|
);
|
|
649
|
+
|
|
649
650
|
let curFlyout = <FlyoutMenu depth={1} />;
|
|
650
651
|
for (let i = 2; i < numFlyouts - 1; i++) {
|
|
651
652
|
curFlyout = <FlyoutMenu depth={i}>{curFlyout}</FlyoutMenu>;
|
package/src/demos/Nav.md
CHANGED
|
@@ -1412,3 +1412,108 @@ class PageLayoutManualNav extends React.Component {
|
|
|
1412
1412
|
}
|
|
1413
1413
|
}
|
|
1414
1414
|
```
|
|
1415
|
+
|
|
1416
|
+
### Flyout nav
|
|
1417
|
+
|
|
1418
|
+
```js isFullscreen
|
|
1419
|
+
import React from 'react';
|
|
1420
|
+
import {
|
|
1421
|
+
Page,
|
|
1422
|
+
Nav,
|
|
1423
|
+
NavList,
|
|
1424
|
+
NavItem,
|
|
1425
|
+
PageHeader,
|
|
1426
|
+
PageHeaderTools,
|
|
1427
|
+
PageSidebar,
|
|
1428
|
+
PageSection,
|
|
1429
|
+
PageSectionVariants,
|
|
1430
|
+
Menu,
|
|
1431
|
+
MenuContent,
|
|
1432
|
+
MenuList,
|
|
1433
|
+
MenuItem
|
|
1434
|
+
} from '@patternfly/react-core';
|
|
1435
|
+
import DashboardHeader from './examples/DashboardHeader';
|
|
1436
|
+
|
|
1437
|
+
class VerticalPage extends React.Component {
|
|
1438
|
+
constructor(props) {
|
|
1439
|
+
super(props);
|
|
1440
|
+
this.state = {
|
|
1441
|
+
isNavOpen: true,
|
|
1442
|
+
activeItem: 0,
|
|
1443
|
+
};
|
|
1444
|
+
this.onNavSelect = result => {
|
|
1445
|
+
this.setState({
|
|
1446
|
+
activeItem: result.itemId
|
|
1447
|
+
});
|
|
1448
|
+
};
|
|
1449
|
+
this.onMenuSelect = (event, itemId) => {
|
|
1450
|
+
this.setState({
|
|
1451
|
+
activeItem: itemId
|
|
1452
|
+
});
|
|
1453
|
+
};
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
render() {
|
|
1457
|
+
const numFlyouts = 5;
|
|
1458
|
+
const FlyoutMenu = ({ depth, children }) => (
|
|
1459
|
+
<Menu key={depth} containsFlyout isNavFlyout id={`menu-${depth}`} onSelect={this.onMenuSelect}>
|
|
1460
|
+
<MenuContent>
|
|
1461
|
+
<MenuList>
|
|
1462
|
+
<MenuItem flyoutMenu={children} itemId={`next-menu-${depth}`} to={`#menu-link-${depth}`}>
|
|
1463
|
+
Additional settings
|
|
1464
|
+
</MenuItem>
|
|
1465
|
+
{[...Array(numFlyouts - depth).keys()].map(j => (
|
|
1466
|
+
<MenuItem key={`${depth}-${j}`} itemId={`${depth}-${j}`} to={`#menu-link-${depth}-${j}`}>
|
|
1467
|
+
Settings menu {depth} item {j}
|
|
1468
|
+
</MenuItem>
|
|
1469
|
+
))}
|
|
1470
|
+
<MenuItem flyoutMenu={children} itemId={`next-menu-2-${depth}`} to={`#second-menu-link-${depth}`}>
|
|
1471
|
+
Additional settings
|
|
1472
|
+
</MenuItem>
|
|
1473
|
+
</MenuList>
|
|
1474
|
+
</MenuContent>
|
|
1475
|
+
</Menu>
|
|
1476
|
+
);
|
|
1477
|
+
let curFlyout = <FlyoutMenu depth={1} />;
|
|
1478
|
+
for (let i = 2; i < numFlyouts - 1; i++) {
|
|
1479
|
+
curFlyout = <FlyoutMenu depth={i}>{curFlyout}</FlyoutMenu>;
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
const { activeItem } = this.state;
|
|
1483
|
+
|
|
1484
|
+
const Sidebar = (
|
|
1485
|
+
<PageSidebar
|
|
1486
|
+
nav={
|
|
1487
|
+
<Nav onSelect={this.onNavSelect}>
|
|
1488
|
+
<NavList>
|
|
1489
|
+
<NavItem id="flyout-link1" to="#flyout-link1" itemId={0} isActive={activeItem === 0}>
|
|
1490
|
+
System Panel
|
|
1491
|
+
</NavItem>
|
|
1492
|
+
<NavItem
|
|
1493
|
+
flyout={curFlyout}
|
|
1494
|
+
id="flyout-link2"
|
|
1495
|
+
to="#flyout-link2"
|
|
1496
|
+
itemId={1}
|
|
1497
|
+
isActive={activeItem === 1}
|
|
1498
|
+
>
|
|
1499
|
+
Settings
|
|
1500
|
+
</NavItem>
|
|
1501
|
+
<NavItem id="flyout-link3" to="#flyout-link3" itemId={2} isActive={activeItem === 2}>
|
|
1502
|
+
Authentication
|
|
1503
|
+
</NavItem>
|
|
1504
|
+
</NavList>
|
|
1505
|
+
</Nav>
|
|
1506
|
+
}
|
|
1507
|
+
/>
|
|
1508
|
+
);
|
|
1509
|
+
|
|
1510
|
+
return (
|
|
1511
|
+
<Page header={<DashboardHeader />} sidebar={Sidebar} isManagedSidebar>
|
|
1512
|
+
<PageSection variant={PageSectionVariants.darker}>Section with darker background</PageSection>
|
|
1513
|
+
<PageSection variant={PageSectionVariants.dark}>Section with dark background</PageSection>
|
|
1514
|
+
<PageSection variant={PageSectionVariants.light}>Section with light background</PageSection>
|
|
1515
|
+
</Page>
|
|
1516
|
+
);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
```
|