@patternfly/react-core 4.267.2 → 4.267.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.267.2",
3
+ "version": "4.267.3",
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",
@@ -77,5 +77,5 @@
77
77
  "react": "^16.8 || ^17 || ^18",
78
78
  "react-dom": "^16.8 || ^17 || ^18"
79
79
  },
80
- "gitHead": "d0a31d9e7658776d5a4fd38beb13584fb90df4b8"
80
+ "gitHead": "2f30f0c83a0077a70180472f74d6825f6db023b2"
81
81
  }
@@ -22,7 +22,7 @@ export interface MenuItemProps extends Omit<React.HTMLProps<HTMLLIElement>, 'onC
22
22
  className?: string;
23
23
  /** Identifies the component in the Menu onSelect or onActionClick callback */
24
24
  itemId?: any;
25
- /** Target navigation link */
25
+ /** Target navigation link. Should not be used if the flyout prop is defined. */
26
26
  to?: string;
27
27
  /** @beta Flag indicating the item has a checkbox */
28
28
  hasCheck?: boolean;
@@ -54,7 +54,7 @@ export interface MenuItemProps extends Omit<React.HTMLProps<HTMLLIElement>, 'onC
54
54
  isFocused?: boolean;
55
55
  /** Flag indicating the item is in danger state */
56
56
  isDanger?: boolean;
57
- /** @beta Flyout menu */
57
+ /** @beta Flyout menu. Should not be used if the to prop is defined. */
58
58
  flyoutMenu?: React.ReactElement;
59
59
  /** @beta Callback function when mouse leaves trigger */
60
60
  onShowFlyout?: (event?: any) => void;
@@ -202,6 +202,7 @@ const MenuItemBase: React.FunctionComponent<MenuItemProps> = ({
202
202
 
203
203
  if (key === ' ' || key === 'Enter' || key === 'ArrowRight' || type === 'click') {
204
204
  event.stopPropagation();
205
+ event.preventDefault();
205
206
  if (!flyoutVisible) {
206
207
  showFlyout(true);
207
208
  setFlyoutTarget(target as HTMLElement);
@@ -14,7 +14,7 @@ export interface NavItemProps extends Omit<React.HTMLProps<HTMLAnchorElement>, '
14
14
  styleChildren?: boolean;
15
15
  /** Additional classes added to the nav item */
16
16
  className?: string;
17
- /** Target navigation link */
17
+ /** Target navigation link. Should not be used if the flyout prop is defined. */
18
18
  to?: string;
19
19
  /** Flag indicating whether the item is active */
20
20
  isActive?: boolean;
@@ -28,7 +28,7 @@ export interface NavItemProps extends Omit<React.HTMLProps<HTMLAnchorElement>, '
28
28
  onClick?: NavSelectClickHandler;
29
29
  /** Component used to render NavItems if React.isValidElement(children) is false */
30
30
  component?: React.ReactNode;
31
- /** Flyout of a nav item. This should be a Menu component. */
31
+ /** Flyout of a nav item. This should be a Menu component. Should not be used if the to prop is defined. */
32
32
  flyout?: React.ReactElement;
33
33
  /** Callback when flyout is opened or closed */
34
34
  onShowFlyout?: () => void;
@@ -68,8 +68,14 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
68
68
  const ref = React.useRef<HTMLLIElement>();
69
69
  const flyoutVisible = ref === flyoutRef;
70
70
  const popperRef = React.useRef<HTMLDivElement>();
71
- const Component = component as any;
72
71
  const hasFlyout = flyout !== undefined;
72
+ const Component = hasFlyout ? 'button' : (component as any);
73
+
74
+ // A NavItem should not be both a link and a flyout
75
+ if (to && hasFlyout) {
76
+ // eslint-disable-next-line no-console
77
+ console.error('NavItem cannot have both "to" and "flyout" props.');
78
+ }
73
79
 
74
80
  const showFlyout = (show: boolean, override?: boolean) => {
75
81
  if ((!flyoutVisible || override) && show) {
@@ -106,11 +112,7 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
106
112
  const key = event.key;
107
113
  const target = event.target as HTMLElement;
108
114
 
109
- if (!(popperRef?.current?.contains(target) || (hasFlyout && ref?.current?.contains(target)))) {
110
- return;
111
- }
112
-
113
- if (key === ' ' || key === 'ArrowRight') {
115
+ if ((key === ' ' || key === 'Enter' || key === 'ArrowRight') && hasFlyout && ref?.current?.contains(target)) {
114
116
  event.stopPropagation();
115
117
  event.preventDefault();
116
118
  if (!flyoutVisible) {
@@ -119,7 +121,9 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
119
121
  }
120
122
  }
121
123
 
122
- if (key === 'Escape' || key === 'ArrowLeft') {
124
+ // We only want the NavItem to handle closing a flyout menu if only the first level flyout is open.
125
+ // Otherwise, MenuItem should handle closing its flyouts
126
+ if ((key === 'Escape' || key === 'ArrowLeft') && popperRef?.current?.querySelectorAll('.pf-c-menu').length === 1) {
123
127
  if (flyoutVisible) {
124
128
  event.stopPropagation();
125
129
  event.preventDefault();
@@ -165,6 +169,8 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
165
169
  'aria-expanded': flyoutVisible
166
170
  };
167
171
 
172
+ const tabIndex = isNavOpen ? null : -1;
173
+
168
174
  const renderDefaultLink = (context: any): React.ReactNode => {
169
175
  const preventLinkDefault = preventDefault || !to;
170
176
  return (
@@ -178,7 +184,7 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
178
184
  className
179
185
  )}
180
186
  aria-current={isActive ? 'page' : null}
181
- tabIndex={isNavOpen ? null : '-1'}
187
+ tabIndex={tabIndex}
182
188
  {...(hasFlyout && { ...ariaFlyoutProps })}
183
189
  {...props}
184
190
  >
@@ -195,7 +201,7 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
195
201
  ...(styleChildren && {
196
202
  className: css(styles.navLink, isActive && styles.modifiers.current, child.props && child.props.className)
197
203
  }),
198
- tabIndex: child.props.tabIndex || isNavOpen ? null : -1,
204
+ tabIndex: child.props.tabIndex || tabIndex,
199
205
  children: hasFlyout ? (
200
206
  <React.Fragment>
201
207
  {child.props.children}
@@ -19,12 +19,7 @@ export const NavFlyout: React.FunctionComponent = () => {
19
19
  <Menu key={depth} containsFlyout isNavFlyout id={`nav-flyout-menu-${depth}`} onSelect={onMenuSelect}>
20
20
  <MenuContent>
21
21
  <MenuList>
22
- <MenuItem
23
- onClick={onMenuItemClick}
24
- flyoutMenu={children}
25
- itemId={`nav-flyout-next-menu-${depth}`}
26
- to={`#next-menu-link-${depth}`}
27
- >
22
+ <MenuItem onClick={onMenuItemClick} flyoutMenu={children} itemId={`nav-flyout-next-menu-${depth}`}>
28
23
  Next menu
29
24
  </MenuItem>
30
25
  {Array.apply(0, Array(numFlyouts - depth)).map((_item, index: number) => (
@@ -38,12 +33,7 @@ export const NavFlyout: React.FunctionComponent = () => {
38
33
  Menu {depth} item {index}
39
34
  </MenuItem>
40
35
  ))}
41
- <MenuItem
42
- onClick={onMenuItemClick}
43
- flyoutMenu={children}
44
- itemId={`nav-flyout-next-menu-2-${depth}`}
45
- to={`#next-menu-2-link-${depth}`}
46
- >
36
+ <MenuItem onClick={onMenuItemClick} flyoutMenu={children} itemId={`nav-flyout-next-menu-2-${depth}`}>
47
37
  Next menu
48
38
  </MenuItem>
49
39
  </MenuList>
@@ -81,7 +71,6 @@ export const NavFlyout: React.FunctionComponent = () => {
81
71
  preventDefault
82
72
  flyout={curFlyout}
83
73
  id="nav-flyout-default-link-3"
84
- to="#nav-flyout-default-link-3"
85
74
  itemId="nav-flyout-default-link-3"
86
75
  isActive={activeItem === 'nav-flyout-default-link-3'}
87
76
  >
package/src/demos/Nav.md CHANGED
@@ -1463,7 +1463,7 @@ class VerticalPage extends React.Component {
1463
1463
  <Menu key={depth} containsFlyout isNavFlyout id={`menu-${depth}`} onSelect={this.onMenuSelect}>
1464
1464
  <MenuContent>
1465
1465
  <MenuList>
1466
- <MenuItem flyoutMenu={children} itemId={`next-menu-${depth}`} to={`#menu-link-${depth}`}>
1466
+ <MenuItem flyoutMenu={children} itemId={`next-menu-${depth}`}>
1467
1467
  Additional settings
1468
1468
  </MenuItem>
1469
1469
  {[...Array(numFlyouts - depth).keys()].map(j => (
@@ -1471,7 +1471,7 @@ class VerticalPage extends React.Component {
1471
1471
  Settings menu {depth} item {j}
1472
1472
  </MenuItem>
1473
1473
  ))}
1474
- <MenuItem flyoutMenu={children} itemId={`next-menu-2-${depth}`} to={`#second-menu-link-${depth}`}>
1474
+ <MenuItem flyoutMenu={children} itemId={`next-menu-2-${depth}`}>
1475
1475
  Additional settings
1476
1476
  </MenuItem>
1477
1477
  </MenuList>