Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 677
Add TrailingAction support to NavList#4697
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
2a2f3c22c9a5b1c3d313920d6c6b910566381d330a8cbd87fcb6ff9b8de3535057ff7c646110e46f8083ca827edfd199464dd7f35786bcc55449c5f574080cc2d35340ea3d9f2cd374627e01a8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@primer/react": minor | ||
| --- | ||
| Add TrailingAction support to NavList |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import {test, expect} from '@playwright/test' | ||
| import {visit} from '../test-helpers/storybook' | ||
| import {themes} from '../test-helpers/themes' | ||
| test.describe('NavList', () => { | ||
| test.describe('With TrailingAction', () => { | ||
| for (const theme of themes) { | ||
| test.describe(theme, () => { | ||
| test('default @vrt', async ({page}) => { | ||
| await visit(page, { | ||
| id: 'components-navlist--with-trailing-action', | ||
| globals: { | ||
| colorScheme: theme, | ||
| }, | ||
| }) | ||
| // Default state | ||
| expect(await page.screenshot()).toMatchSnapshot(`NavList.With TrailingAction.${theme}.png`) | ||
| }) | ||
| test('axe @aat', async ({page}) => { | ||
| await visit(page, { | ||
| id: 'components-navlist--with-trailing-action', | ||
| globals: { | ||
| colorScheme: theme, | ||
| }, | ||
| }) | ||
| await expect(page).toHaveNoViolations() | ||
| }) | ||
| }) | ||
| } | ||
| }) | ||
| test.describe('With Bad Example of SubNav and TrailingAction', () => { | ||
| for (const theme of themes) { | ||
| test.describe(theme, () => { | ||
| test('default @vrt', async ({page}) => { | ||
| await visit(page, { | ||
| id: 'components-navlist-devonly--with-bad-example-of-sub-nav-and-trailing-action', | ||
| globals: { | ||
| colorScheme: theme, | ||
| }, | ||
| }) | ||
| // Default state | ||
| expect(await page.screenshot()).toMatchSnapshot( | ||
| `NavList.With Bad Example of SubNav and TrailingAction.${theme}.png`, | ||
| ) | ||
| }) | ||
| test('axe @aat', async ({page}) => { | ||
| await visit(page, { | ||
| id: 'components-navlist-devonly--with-bad-example-of-sub-nav-and-trailing-action', | ||
| globals: { | ||
| colorScheme: theme, | ||
| }, | ||
| }) | ||
| await expect(page).toHaveNoViolations() | ||
| }) | ||
| }) | ||
| } | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import type {Meta} from '@storybook/react' | ||
| import React from 'react' | ||
| import {PageLayout} from '../PageLayout' | ||
| import {NavList} from './NavList' | ||
| import {ArrowRightIcon, ArrowLeftIcon, BookIcon, FileDirectoryIcon} from '@primer/octicons-react' | ||
| const meta: Meta = { | ||
| title: 'Components/NavList/DevOnly', | ||
| component: NavList, | ||
| parameters: { | ||
| layout: 'fullscreen', | ||
| }, | ||
| } | ||
| export const WithBadExampleOfSubNavAndTrailingAction = () => { | ||
| return ( | ||
| <PageLayout> | ||
| <PageLayout.Pane position="start"> | ||
| <NavList> | ||
| <NavList.Item> | ||
| <NavList.LeadingVisual> | ||
| <FileDirectoryIcon /> | ||
| </NavList.LeadingVisual> | ||
| Item 1 | ||
| <NavList.TrailingAction label="Expand sidebar" icon={ArrowLeftIcon} /> | ||
| </NavList.Item> | ||
| <NavList.Item> | ||
| Item 2 | ||
| <NavList.TrailingAction as="a" href="#" label="Some action" icon={ArrowRightIcon} /> | ||
| </NavList.Item> | ||
| <NavList.Item> | ||
| Item 3 | ||
| <NavList.TrailingAction label="This is not supported and should not render!!!!!" icon={BookIcon} /> | ||
| <NavList.SubNav> | ||
| <NavList.Item href="#"> | ||
| Sub item 1 | ||
| <NavList.TrailingAction label="Another action" icon={BookIcon} /> | ||
| </NavList.Item> | ||
| </NavList.SubNav> | ||
| </NavList.Item> | ||
| </NavList> | ||
| </PageLayout.Pane> | ||
| </PageLayout> | ||
| ) | ||
| } | ||
| WithBadExampleOfSubNavAndTrailingAction.storyName = 'With SubNav and Trailing Action (Bad example, do not copy)' | ||
| export default meta |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,7 +2,12 @@ import {ChevronDownIcon} from '@primer/octicons-react' | ||
| import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic' | ||
| import React, {isValidElement} from 'react' | ||
| import styled from 'styled-components' | ||
| import type {ActionListDividerProps, ActionListLeadingVisualProps, ActionListTrailingVisualProps} from '../ActionList' | ||
| import type { | ||
| ActionListTrailingActionProps, | ||
| ActionListDividerProps, | ||
| ActionListLeadingVisualProps, | ||
| ActionListTrailingVisualProps, | ||
| } from '../ActionList' | ||
| import {ActionList} from '../ActionList' | ||
| import {ActionListContainerContext} from '../ActionList/ActionListContainerContext' | ||
| import Box from '../Box' | ||
| @@ -65,9 +70,9 @@ const Item = React.forwardRef<HTMLAnchorElement, NavListItemProps>( | ||
| // Get SubNav from children | ||
| const subNav = React.Children.toArray(children).find(child => isValidElement(child) && child.type === SubNav) | ||
| // Get children without SubNav | ||
| const childrenWithoutSubNav = React.Children.toArray(children).filter(child => | ||
| isValidElement(child) ? child.type !== SubNav : true, | ||
| // Get children without SubNav or TrailingAction | ||
| const childrenWithoutSubNavOrTrailingAction = React.Children.toArray(children).filter(child => | ||
| isValidElement(child) ? child.type !== SubNav && child.type !== TrailingAction : true, | ||
| ) | ||
| if (!isValidElement(subNav) && defaultOpen) | ||
| @@ -78,7 +83,7 @@ const Item = React.forwardRef<HTMLAnchorElement, NavListItemProps>( | ||
| if (subNav && isValidElement(subNav)) { | ||
| return ( | ||
| <ItemWithSubNav subNav={subNav} depth={depth} defaultOpen={defaultOpen} sx={sxProp}> | ||
| {childrenWithoutSubNav} | ||
| {childrenWithoutSubNavOrTrailingAction} | ||
| </ItemWithSubNav> | ||
| ) | ||
| } | ||
| @@ -251,6 +256,14 @@ const Divider = ActionList.Divider | ||
| Divider.displayName = 'NavList.Divider' | ||
| // NavList.TrailingAction | ||
| export type NavListTrailingActionProps = ActionListTrailingActionProps | ||
| const TrailingAction = ActionList.TrailingAction | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right! I think we should disallow it. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been addressed in this diff. Let me know what you think of this approach! I've supplemented this with:
| ||
| TrailingAction.displayName = 'NavList.TrailingAction' | ||
| // ---------------------------------------------------------------------------- | ||
| // NavList.Group | ||
| @@ -285,6 +298,7 @@ export const NavList = Object.assign(Root, { | ||
| SubNav, | ||
| LeadingVisual, | ||
| TrailingVisual, | ||
| TrailingAction, | ||
| Divider, | ||
| Group, | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: A story showing this feature within sub items could be cool!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
See Storybook: WithTrailingActionInSubItem