Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Nav): Updated to add wrapper for nav link text #9740

Merged
merged 6 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/react-core/src/components/Nav/NavExpandable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { PickOptional } from '../../helpers/typeUtils';
import { getOUIAProps, OUIAProps, getDefaultOUIAId } from '../../helpers';

export interface NavExpandableProps
extends React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>,
extends Omit<React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, 'title'>,
OUIAProps {
/** Title shown for the expandable list */
title: string;
/** Title content shown for the expandable list */
title: React.ReactNode;
/** If defined, screen readers will read this text instead of the list title */
srText?: string;
/** Boolean to programatically expand or collapse section */
Expand Down Expand Up @@ -126,14 +126,14 @@ class NavExpandable extends React.Component<NavExpandableProps, NavExpandableSta
<PageSidebarContext.Consumer>
{({ isSidebarOpen }) => (
<button
className={styles.navLink}
className={css(styles.navLink)}
id={srText ? null : this.id}
onClick={(event) => this.onExpand(event, context.onToggle)}
aria-expanded={expandedState}
tabIndex={isSidebarOpen ? null : -1}
{...buttonProps}
>
{title}
{typeof title !== 'string' ? <span className={css(`${styles.nav}__link-text`)}>{title}</span> : title}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, only other thing is that we're having this wrapper be an opt-in for the NavItem, but providing logic here to determine if the wrapper is used or not. It seems like we'd want it to be opt in in both places?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is not opt in here because we did not have the ability to pass a react node before. Menaing. that it is a new feature. We will not be breaking anyone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we open an issue to make this the default in the next breaking change, if there isn't one already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcoker breaking change issue opened #9755

<span className={css(styles.navToggle)}>
<span className={css(styles.navToggleIcon)}>
<AngleRightIcon aria-hidden="true" />
Expand Down
5 changes: 4 additions & 1 deletion packages/react-core/src/components/Nav/NavItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export interface NavItemProps extends Omit<React.HTMLProps<HTMLAnchorElement>, '
ouiaId?: number | string;
/** 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. */
ouiaSafe?: boolean;
/** @beta Adds a wrapper around the nav link text. Improves the layout when the text is a react node. */
hasNavLinkWrapper?: boolean;
}

export const NavItem: React.FunctionComponent<NavItemProps> = ({
Expand All @@ -56,6 +58,7 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
ouiaId,
ouiaSafe,
zIndex = 9999,
hasNavLinkWrapper,
...props
}: NavItemProps) => {
const { flyoutRef, setFlyoutRef, navRef } = React.useContext(NavContext);
Expand Down Expand Up @@ -188,7 +191,7 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
{...(hasFlyout && { ...ariaFlyoutProps })}
{...props}
>
{children}
{hasNavLinkWrapper ? <span className={css(`${styles.nav}__link-text`)}>{children}</span> : children}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

{flyout && flyoutButton}
</Component>
);
Expand Down
9 changes: 9 additions & 0 deletions packages/react-core/src/components/Nav/examples/Nav.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ ouia: true
---

import './nav.css';
import ArrowRightIcon from '@patternfly/react-icons/dist/esm/icons/arrow-right-icon';
import UserIcon from '@patternfly/react-icons/dist/esm/icons/user-icon';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import UserIcon from '@patternfly/react-icons/dist/esm/icons/user-icon';
import UserIcon from '@patternfly/react-icons/dist/esm/icons/user-icon';



## Examples

Expand Down Expand Up @@ -68,6 +71,12 @@ A flyout should be a `Menu` component. Press `space` or `right arrow` to open a

```

### Link text
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I feel like the example name could be tweaked a little, something like "With text and icon" or "Custom link text" or something. Not sure if "link text" fully conveys what the example is showing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know that the use case is specifically for an icon. You can pass any react node.


```ts isBeta file="./NavLinkText.tsx"

```

## Types

### NavSelectClickHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const NavExpandableThirdLevel: React.FunctionComponent = () => {
</NavItem>
</NavExpandable>
<NavExpandable
title="Expandable section title 2"
title={'Expandable section title 2'}
groupId="nav-expand3rd-group-2"
isActive={activeGroup === 'nav-expand3rd-group-2'}
isExpanded
Expand Down
107 changes: 107 additions & 0 deletions packages/react-core/src/components/Nav/examples/NavLinkText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React from 'react';
import { Nav, NavExpandable, NavItem, NavList } from '@patternfly/react-core';
import ArrowRightIcon from '@patternfly/react-icons/dist/esm/icons/arrow-right-icon';
import UserIcon from '@patternfly/react-icons/dist/esm/icons/user-icon';

export const NavLinkText: React.FunctionComponent = () => {
const [activeGroup, setActiveGroup] = React.useState('nav-expand3rd-group-1');
const [activeItem, setActiveItem] = React.useState('nav-expand3rd-group-1_item-1');

const onSelect = (
_event: React.FormEvent<HTMLInputElement>,
result: { itemId: number | string; groupId: number | string }
) => {
setActiveGroup(result.groupId as string);
setActiveItem(result.itemId as string);
};

const onToggle = (
_event: React.MouseEvent<HTMLButtonElement>,
result: { groupId: number | string; isExpanded: boolean }
) => {
// eslint-disable-next-line no-console
console.log(`Group ${result.groupId} expanded? ${result.isExpanded}`);
};

return (
<Nav onSelect={onSelect} onToggle={onToggle} aria-label="Nav link text">
<NavList>
<NavItem
preventDefault
id="link-text-link-1"
to="#link-text-link-1"
itemId="link-text-1-item-1"
isActive={activeItem === 'link-text-1-item-1'}
hasNavLinkWrapper
>
Link 1
<ArrowRightIcon />
</NavItem>
<NavExpandable
title={
<>
Link 2<small>(small text)</small>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a space

Suggested change
Link 2<small>(small text)</small>
Link 2 <small>(small text)</small>

</>
}
groupId="link-text-group-1"
isActive={activeGroup === 'link-text-group-1'}
isExpanded
>
<NavItem
preventDefault
id="link-text-link-2"
to="#link-text-link-2"
groupId="link-text-group-1"
itemId="link-text-group-1_item-1"
isActive={activeItem === 'link-text-group-1_item-1'}
>
<UserIcon />
Subnav link 1
Comment on lines +59 to +60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to add hasNavLinkWrapper to this and the one below? With adding the space to the 2 items I left comments about, and adding hasNavLinkWrapper here and the next item, it would look like this:

Screenshot 2023-10-17 at 1 59 55 PM

Here's what it looks like now:

Screenshot 2023-10-17 at 2 00 15 PM

</NavItem>
<NavItem
preventDefault
id="link-text-link-3"
to="#link-text-link-3"
groupId="link-text-group-1"
itemId="link-text-group-1_item-2"
isActive={activeItem === 'link-text-group-1_item-2'}
>
<UserIcon />
Subnav link 2
</NavItem>
</NavExpandable>
<NavExpandable
title={
<>
Link 3<strong>(strong text)</strong>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Link 3<strong>(strong text)</strong>
Link 3 <strong>(strong text)</strong>

</>
}
groupId="link-text-group-2"
isActive={activeGroup === 'nav-expand3rd-group-2'}
isExpanded
>
<NavItem
preventDefault
id="link-text-link-4"
to="link-text-link-4"
groupId="link-text-group-2"
itemId="link-text-group-2_item-1"
isActive={activeItem === 'link-text-group-2_item-1'}
>
Subnav link 1
</NavItem>
<NavItem
preventDefault
id="link-text-link-5"
to="link-text-link-5"
groupId="link-text-group-2"
itemId="link-text-group-2_item-2"
isActive={activeItem === 'link-text-group-2_item-2'}
>
Subnav link 2
</NavItem>
</NavExpandable>
</NavList>
</Nav>
);
};
1 change: 1 addition & 0 deletions packages/react-core/src/components/Nav/examples/nav.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ws-react-c-navigation-expandable-wsubnavigation-titles,
#ws-react-c-navigation-mixed,
#ws-react-c-navigation-expandable-third-level,
#ws-react-c-navigation-link-text,
#ws-react-c-navigation-horizontal-subnav,
#ws-react-c-navigation-flyout,
#ws-react-c-navigation-drilldown {
Expand Down
Loading