Skip to content

Commit dba392d

Browse files
authored
feat(Navigation): Penta updates for nav (#9948)
* feat(Navigation): Penta updates for nav
1 parent a90b9d4 commit dba392d

File tree

29 files changed

+408
-926
lines changed

29 files changed

+408
-926
lines changed

packages/react-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"tslib": "^2.5.0"
5555
},
5656
"devDependencies": {
57-
"@patternfly/patternfly": "6.0.0-alpha.49",
57+
"@patternfly/patternfly": "6.0.0-alpha.51",
5858
"@rollup/plugin-commonjs": "^25.0.0",
5959
"@rollup/plugin-node-resolve": "^15.0.2",
6060
"@rollup/plugin-replace": "^5.0.2",

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ export interface NavProps
3535
) => void;
3636
/** Accessible label for the nav when there are multiple navs on the page */
3737
'aria-label'?: string;
38-
/** Indicates which theme color to use */
39-
theme?: 'dark' | 'light';
4038
/** For horizontal navs */
41-
variant?: 'default' | 'horizontal' | 'tertiary' | 'horizontal-subnav';
39+
variant?: 'default' | 'horizontal' | 'horizontal-subnav';
4240
/** Value to overwrite the randomly generated data-ouia-component-id.*/
4341
ouiaId?: number | string;
4442
/** Set the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false. */
@@ -72,7 +70,6 @@ class Nav extends React.Component<
7270
static defaultProps: NavProps = {
7371
onSelect: () => undefined,
7472
onToggle: () => undefined,
75-
theme: 'dark',
7673
ouiaSafe: true
7774
};
7875

@@ -121,13 +118,12 @@ class Nav extends React.Component<
121118
onSelect,
122119
// eslint-disable-next-line @typescript-eslint/no-unused-vars
123120
onToggle,
124-
theme,
125121
ouiaId,
126122
ouiaSafe,
127123
variant,
128124
...props
129125
} = this.props;
130-
const isHorizontal = ['horizontal', 'tertiary'].includes(variant);
126+
const isHorizontal = ['horizontal', 'horizontal-subnav'].includes(variant);
131127

132128
return (
133129
<NavContext.Provider
@@ -148,7 +144,7 @@ class Nav extends React.Component<
148144
onToggle: (event: React.MouseEvent<HTMLButtonElement>, groupId: number | string, expanded: boolean) =>
149145
this.onToggle(event, groupId, expanded),
150146
updateIsScrollable: (isScrollable: boolean) => this.setState({ isScrollable }),
151-
isHorizontal: ['horizontal', 'tertiary', 'horizontal-subnav'].includes(variant),
147+
isHorizontal: ['horizontal', 'horizontal-subnav'].includes(variant),
152148
flyoutRef: this.state.flyoutRef,
153149
setFlyoutRef: (flyoutRef) => this.setState({ flyoutRef }),
154150
navRef: this.navRef
@@ -157,14 +153,12 @@ class Nav extends React.Component<
157153
<nav
158154
className={css(
159155
styles.nav,
160-
theme === 'light' && styles.modifiers.light,
161156
isHorizontal && styles.modifiers.horizontal,
162-
variant === 'tertiary' && styles.modifiers.tertiary,
163-
variant === 'horizontal-subnav' && styles.modifiers.horizontalSubnav,
157+
variant === 'horizontal-subnav' && styles.modifiers.subnav,
164158
this.state.isScrollable && styles.modifiers.scrollable,
165159
className
166160
)}
167-
aria-label={ariaLabel || (['tertiary', 'horizontal-subnav'].includes(variant) ? 'Local' : 'Global')}
161+
aria-label={ariaLabel || (variant === 'horizontal-subnav' ? 'Local' : 'Global')}
168162
ref={this.navRef}
169163
{...getOUIAProps(Nav.displayName, ouiaId !== undefined ? ouiaId : this.state.ouiaStateId, ouiaSafe)}
170164
{...props}

packages/react-core/src/components/Nav/NavExpandable.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ class NavExpandable extends React.Component<NavExpandableProps, NavExpandableSta
115115
<li
116116
className={css(
117117
styles.navItem,
118-
styles.modifiers.expandable,
119118
expandedState && styles.modifiers.expanded,
120119
isActive && styles.modifiers.current,
121120
className

packages/react-core/src/components/Nav/NavItem.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as React from 'react';
22
import styles from '@patternfly/react-styles/css/components/Nav/nav';
3+
import menuStyles from '@patternfly/react-styles/css/components/Menu/menu';
4+
import dividerStyles from '@patternfly/react-styles/css/components/Divider/divider';
35
import { css } from '@patternfly/react-styles';
46
import { NavContext, NavSelectClickHandler } from './Nav';
57
import { PageSidebarContext } from '../Page/PageSidebar';
@@ -125,7 +127,7 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
125127
// Otherwise, MenuItem should handle closing its flyouts
126128
if (
127129
(key === 'Escape' || key === 'ArrowLeft') &&
128-
popperRef?.current?.querySelectorAll(`.${styles.menu}`).length === 1
130+
popperRef?.current?.querySelectorAll(`.${menuStyles.menu}`).length === 1
129131
) {
130132
if (flyoutVisible) {
131133
event.stopPropagation();
@@ -151,7 +153,7 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
151153
if (flyoutVisible) {
152154
const flyoutItems = Array.from(
153155
(popperRef.current as HTMLElement).getElementsByTagName('UL')[0].children
154-
).filter((el) => !(el.classList.contains('pf-m-disabled') || el.classList.contains(styles.divider)));
156+
).filter((el) => !(el.classList.contains('pf-m-disabled') || el.classList.contains(dividerStyles.divider)));
155157
(flyoutItems[0].firstChild as HTMLElement).focus();
156158
} else {
157159
flyoutTarget.focus();

packages/react-core/src/components/Nav/NavList.tsx

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import styles from '@patternfly/react-styles/css/components/Nav/nav';
33
import { css } from '@patternfly/react-styles';
4+
import { Button } from '../Button';
45
import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon';
56
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
67
import { getLanguageDirection, isElementInView } from '../../helpers/util';
@@ -143,15 +144,19 @@ class NavList extends React.Component<NavListProps> {
143144
{({ isSidebarOpen }) => (
144145
<React.Fragment>
145146
{isHorizontal && (
146-
<button
147-
className={css(styles.navScrollButton)}
148-
aria-label={backScrollAriaLabel || ariaLeftScroll}
149-
onClick={this.scrollBack}
150-
disabled={scrollViewAtStart}
151-
tabIndex={isSidebarOpen ? null : -1}
152-
>
153-
<AngleLeftIcon />
154-
</button>
147+
<div className={css(styles.navScrollButton)}>
148+
<Button
149+
variant="plain"
150+
aria-label={backScrollAriaLabel || ariaLeftScroll}
151+
onClick={this.scrollBack}
152+
disabled={scrollViewAtStart}
153+
tabIndex={isSidebarOpen ? null : -1}
154+
>
155+
<span className={css(styles.buttonIcon)}>
156+
<AngleLeftIcon />
157+
</span>
158+
</Button>
159+
</div>
155160
)}
156161
<ul
157162
ref={this.navList}
@@ -163,15 +168,19 @@ class NavList extends React.Component<NavListProps> {
163168
{children}
164169
</ul>
165170
{isHorizontal && (
166-
<button
167-
className={css(styles.navScrollButton)}
168-
aria-label={forwardScrollAriaLabel || ariaRightScroll}
169-
onClick={this.scrollForward}
170-
disabled={scrollViewAtEnd}
171-
tabIndex={isSidebarOpen ? null : -1}
172-
>
173-
<AngleRightIcon />
174-
</button>
171+
<div className={css(styles.navScrollButton)}>
172+
<Button
173+
variant="plain"
174+
aria-label={forwardScrollAriaLabel || ariaRightScroll}
175+
onClick={this.scrollForward}
176+
disabled={scrollViewAtEnd}
177+
tabIndex={isSidebarOpen ? null : -1}
178+
>
179+
<span className={css(styles.buttonIcon)}>
180+
<AngleRightIcon />
181+
</span>
182+
</Button>
183+
</div>
175184
)}
176185
</React.Fragment>
177186
)}

packages/react-core/src/components/Nav/__tests__/Generated/__snapshots__/NavExpandable.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`NavExpandable should match snapshot (auto-generated) 1`] = `
44
<DocumentFragment>
55
<li
6-
class="pf-v5-c-nav__item pf-m-expandable ''"
6+
class="pf-v5-c-nav__item ''"
77
data-ouia-component-id="OUIA-Generated-NavExpandable-1"
88
data-ouia-component-type="PF5/NavExpandable"
99
data-ouia-safe="true"

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

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,6 @@ describe('Nav', () => {
6060
expect(asFragment()).toMatchSnapshot();
6161
});
6262

63-
test('Dark Nav List', () => {
64-
const { asFragment } = renderNav(
65-
<Nav className="test=nav-class" theme="dark">
66-
<NavList className="test-nav-list-class">
67-
{props.items.map((item) => (
68-
<NavItem to={item.to} key={item.to} className="test-nav-item-class">
69-
{item.label}
70-
</NavItem>
71-
))}
72-
</NavList>
73-
</Nav>
74-
);
75-
expect(asFragment()).toMatchSnapshot();
76-
});
77-
7863
test('Default Nav List - Trigger item active update', async () => {
7964
const user = userEvent.setup();
8065

@@ -228,24 +213,9 @@ describe('Nav', () => {
228213
expect(asFragment()).toMatchSnapshot();
229214
});
230215

231-
test('Tertiary Nav List', () => {
232-
const { asFragment } = renderNav(
233-
<Nav variant="tertiary">
234-
<NavList>
235-
{props.items.map((item) => (
236-
<NavItem to={item.to} key={item.to}>
237-
{item.label}
238-
</NavItem>
239-
))}
240-
</NavList>
241-
</Nav>
242-
);
243-
expect(asFragment()).toMatchSnapshot();
244-
});
245-
246216
test('Nav List with custom item nodes', () => {
247217
const { asFragment } = renderNav(
248-
<Nav variant="tertiary">
218+
<Nav>
249219
<NavList>
250220
<NavItem to="/components/nav#link1" className="test-nav-item-class">
251221
<div className="my-custom-node">My custom node</div>
@@ -260,7 +230,7 @@ describe('Nav', () => {
260230
const user = userEvent.setup();
261231

262232
const { asFragment } = renderNav(
263-
<Nav variant="tertiary">
233+
<Nav>
264234
<NavList>
265235
<NavItem className="test-nav-item-class" flyout={<div>Flyout test</div>}>
266236
<div className="my-custom-node">My custom node</div>

0 commit comments

Comments
 (0)