Skip to content

Commit 3a8eca7

Browse files
committed
feat(Nav): Added default nav tiem wrapper. Added support for nav item icons
1 parent f955f3f commit 3a8eca7

File tree

8 files changed

+367
-172
lines changed

8 files changed

+367
-172
lines changed

packages/react-core/src/components/DescriptionList/examples/DescriptionList.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ propComponents:
1717

1818
import { Button, DescriptionList, DescriptionListTerm, DescriptionListDescription, DescriptionListGroup, DescriptionListTermHelpText, DescriptionListTermHelpTextButton, Popover, Checkbox, Card } from '@patternfly/react-core';
1919
import PlusCircleIcon from '@patternfly/react-icons/dist/esm/icons/plus-circle-icon';
20-
import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
20+
import Icon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
2121
import BookIcon from '@patternfly/react-icons/dist/esm/icons/book-icon';
2222
import KeyIcon from '@patternfly/react-icons/dist/esm/icons/key-icon';
2323
import GlobeIcon from '@patternfly/react-icons/dist/esm/icons/globe-icon';

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ export interface NavItemProps extends Omit<React.HTMLProps<HTMLAnchorElement>, '
3636
onShowFlyout?: () => void;
3737
/** z-index of the flyout nav item */
3838
zIndex?: number;
39+
/** Icon added before the nav item children. */
40+
icon?: React.ReactNode;
3941
/** Value to overwrite the randomly generated data-ouia-component-id.*/
4042
ouiaId?: number | string;
4143
/** 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. */
4244
ouiaSafe?: boolean;
43-
/** Adds a wrapper around the nav link text. Improves the layout when the text is a react node. */
44-
hasNavLinkWrapper?: boolean;
4545
}
4646

4747
export const NavItem: React.FunctionComponent<NavItemProps> = ({
@@ -60,7 +60,7 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
6060
ouiaId,
6161
ouiaSafe,
6262
zIndex = 9999,
63-
hasNavLinkWrapper,
63+
icon,
6464
...props
6565
}: NavItemProps) => {
6666
const { flyoutRef, setFlyoutRef, navRef } = React.useContext(NavContext);
@@ -193,8 +193,8 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
193193
{...(hasFlyout && { ...ariaFlyoutProps })}
194194
{...props}
195195
>
196-
{hasNavLinkWrapper ? <span className={css(`${styles.nav}__link-text`)}>{children}</span> : children}
197-
{flyout && flyoutButton}
196+
{icon && <span className={css(`${styles.nav}__link-icon`)}>{icon}</span>}
197+
<span className={css(`${styles.nav}__link-text`)}>{children}</span>
198198
</Component>
199199
);
200200
};

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import * as React from 'react';
22

33
import { render, screen } from '@testing-library/react';
44
import userEvent from '@testing-library/user-event';
5+
import '@testing-library/jest-dom';
56

67
import { Nav, NavContext } from '../Nav';
78
import { NavList } from '../NavList';
89
import { NavGroup } from '../NavGroup';
910
import { NavItem } from '../NavItem';
1011
import { NavExpandable } from '../NavExpandable';
1112

13+
import styles from '@patternfly/react-styles/css/components/Nav/nav';
14+
1215
const props = {
1316
items: [
1417
{ to: '#link1', label: 'Link 1' },
@@ -242,4 +245,19 @@ describe('Nav', () => {
242245
await user.hover(screen.getByText('My custom node'));
243246
expect(asFragment()).toMatchSnapshot();
244247
});
248+
249+
test('Nav with icon', () => {
250+
renderNav(
251+
<Nav>
252+
<NavList className="test-nav-icon">
253+
{props.items.map((item) => (
254+
<NavItem to={item.to} key={item.to} icon={<span>this is an icon</span>} className="test-nav-item-class">
255+
{item.label}
256+
</NavItem>
257+
))}
258+
</NavList>
259+
</Nav>
260+
);
261+
expect(screen.getAllByText('this is an icon')[0].parentElement).toHaveClass(`${styles.nav}__link-icon`);
262+
});
245263
});

0 commit comments

Comments
 (0)