-
Notifications
You must be signed in to change notification settings - Fork 626
Breadcrumbs : Add overflow menu for responsive behavior #6664
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
Open
pksjce
wants to merge
50
commits into
main
Choose a base branch
from
pk/breadcrumbs-with-overflow-menu
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,178
−17
Open
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
a7208d4
Spike for breadcrumbs overflow
pksjce 54c9148
Add changeset for breadcrumbs overflow
pksjce dc5dac1
Add review comments and change behavior
pksjce 7df321a
Fix up some issues.
pksjce 611d703
check for zero children
pksjce 1a84b8a
Fix bug with hideRoot
pksjce c567b15
Add test cases
pksjce 35c0971
Add docs
pksjce 901ba0c
Breadcrumbs can have more stories
pksjce f8fd857
Add features stories for breadcrumbs
pksjce f415276
Add wrapped breadcrumbs in story
pksjce 68eba14
Fix for ssr and child key
pksjce f4bba96
Add IconButton
pksjce b55755c
Fix for SSR
pksjce 9477af7
Fix for SSR
pksjce df9aa0f
Final changes for SSR
pksjce fcd8a8e
Rework calculations
pksjce 0a09e45
Tests are passing
pksjce 3b9891a
Small fixes to menu button
pksjce 273a055
Fix styling issues with button
pksjce 08637ae
Fix focus states
pksjce 17a3107
Fix focus states
pksjce ed838f3
Make sure old behavior works
pksjce 1870eff
Fix tests and lint
pksjce 0eaf106
Create eighty-queens-tap.md
pksjce a24d75a
Merge branch 'main' into pk/breadcrumbs-with-overflow-menu
pksjce 40cb6a9
chore(deps-dev): bump the eslint group with 3 updates (#6657)
dependabot[bot] 027f4f6
chore(deps): bump the rollup group with 2 updates (#6659)
dependabot[bot] 7b4921c
chore(deps-dev): bump postcss-mixins from 11.0.1 to 12.1.2 (#6660)
dependabot[bot] bc2749c
chore(deps-dev): bump @github/markdownlint-github from 0.7.0 to 0.8.0…
dependabot[bot] f9c9a2d
feat(mcp): add better primitives output, add coding guidelines tool (…
joshblack 870a8ca
Convert menu to disclosure pattern
pksjce bc99a17
Fix bugs
pksjce 020f0b7
Fix up infinite loop at 1 remaining visible item
pksjce 8cf263e
Remove unnecessary comments
pksjce 23ddd0e
Use ref callback for menu width calculation
pksjce 639a782
Fix up review comments
pksjce 2e367bf
Add feature flags
pksjce a5b9c20
Merge branch 'pk/breadcrumbs-with-overflow-menu' of https://github.co…
pksjce bb5aa77
Delete .changeset/good-cougars-hug.md
pksjce b8063b8
Add different prop to hideRoot
pksjce c7669d6
Add tests
pksjce 5c3fc21
Merge branch 'pk/breadcrumbs-with-overflow-menu' of https://github.co…
pksjce e2f34c5
Merge branch 'main' into pk/breadcrumbs-with-overflow-menu
pksjce a7418b7
Fix lint and test issue
pksjce 7c2ced8
Merge branch 'pk/breadcrumbs-with-overflow-menu' of https://github.co…
pksjce 0846a5a
Dont use story in aat
pksjce 7df8356
Fix for aat
pksjce 92b813e
Story color needs changed
pksjce 2854259
Some css improvements
pksjce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@primer/react": patch | ||
--- | ||
|
||
Breadcrumbs : Add overflow menu for responsive behavior |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
packages/react/src/Breadcrumbs/Breadcrumbs.features.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
import type {Meta} from '@storybook/react-vite' | ||
import type React from 'react' | ||
import {useState} from 'react' | ||
import type {ComponentProps} from '../utils/types' | ||
import Breadcrumbs from './Breadcrumbs' | ||
import TextInput from '../TextInput' | ||
|
||
export default { | ||
title: 'Components/Breadcrumbs/Features', | ||
component: Breadcrumbs, | ||
} as Meta<ComponentProps<typeof Breadcrumbs>> | ||
|
||
export const OverflowWrap = () => ( | ||
<Breadcrumbs overflow="wrap"> | ||
<Breadcrumbs.Item href="#">Home</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Products</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Category</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Subcategory</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Item</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Details</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#" selected> | ||
Current Page | ||
</Breadcrumbs.Item> | ||
</Breadcrumbs> | ||
) | ||
|
||
export const OverflowMenu = () => ( | ||
<Breadcrumbs overflow="menu"> | ||
<Breadcrumbs.Item href="#">Home</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Products</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Category</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Subcategory</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Item</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Details</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#" selected> | ||
Current Page | ||
</Breadcrumbs.Item> | ||
</Breadcrumbs> | ||
) | ||
|
||
export const OverflowMenuShowRoot = () => ( | ||
<Breadcrumbs overflow="menu-with-root"> | ||
<Breadcrumbs.Item href="#">github</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Teams</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Engineering</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">core-productivity</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">collaboration-workflows-flex</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#" selected> | ||
global-navigation-reviewers | ||
</Breadcrumbs.Item> | ||
</Breadcrumbs> | ||
) | ||
|
||
export const OverflowMenuNarrowContainer = () => ( | ||
<div style={{width: '350px', border: '1px solid #ccc', padding: '8px'}}> | ||
<Breadcrumbs overflow="menu"> | ||
<Breadcrumbs.Item href="#">Home</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Products</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Category</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Subcategory</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#" selected> | ||
Current Page | ||
</Breadcrumbs.Item> | ||
</Breadcrumbs> | ||
</div> | ||
) | ||
|
||
// Wrapper components to test that BreadcrumbsItem works when wrapped | ||
const StyledWrapper = ({children}: {children: React.ReactNode}) => ( | ||
<span style={{padding: '2px', border: '1px dotted #999'}}>{children}</span> | ||
) | ||
|
||
const ConditionalWrapper = ({children, condition}: {children: React.ReactNode; condition: boolean}) => { | ||
return condition ? <strong>{children}</strong> : <>{children}</> | ||
} | ||
|
||
const DataAttributeWrapper = ({children}: {children: React.ReactNode}) => ( | ||
<span data-testid="wrapper" className="custom-wrapper"> | ||
{children} | ||
</span> | ||
) | ||
|
||
export const WrappedBreadcrumbItemsWithOverflow = () => ( | ||
<Breadcrumbs overflow="menu"> | ||
<StyledWrapper> | ||
<Breadcrumbs.Item href="#">Wrapped Home</Breadcrumbs.Item> | ||
</StyledWrapper> | ||
<ConditionalWrapper condition={false}> | ||
<Breadcrumbs.Item href="#">Products</Breadcrumbs.Item> | ||
</ConditionalWrapper> | ||
<DataAttributeWrapper> | ||
<Breadcrumbs.Item href="#">Category</Breadcrumbs.Item> | ||
</DataAttributeWrapper> | ||
<StyledWrapper> | ||
<Breadcrumbs.Item href="#">Subcategory</Breadcrumbs.Item> | ||
</StyledWrapper> | ||
<ConditionalWrapper condition={true}> | ||
<Breadcrumbs.Item href="#">Item</Breadcrumbs.Item> | ||
</ConditionalWrapper> | ||
<DataAttributeWrapper> | ||
<Breadcrumbs.Item href="#">Details</Breadcrumbs.Item> | ||
</DataAttributeWrapper> | ||
<Breadcrumbs.Item href="#" selected> | ||
Current Page | ||
</Breadcrumbs.Item> | ||
</Breadcrumbs> | ||
) | ||
|
||
export const WithEditableNameInput = () => ( | ||
<Breadcrumbs> | ||
<Breadcrumbs.Item href="#">Home</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Documents</Breadcrumbs.Item> | ||
<Breadcrumbs.Item href="#">Project Alpha</Breadcrumbs.Item> | ||
<Breadcrumbs.Item> | ||
<TextInput | ||
defaultValue="Untitled Document" | ||
size="small" | ||
sx={{ | ||
minWidth: '120px', | ||
maxWidth: '180px', | ||
fontSize: 'inherit', | ||
border: '1px dashed var(--borderColor-muted)', | ||
'&:focus': { | ||
border: '1px solid var(--borderColor-accent-emphasis)', | ||
}, | ||
}} | ||
aria-label="Edit document name" | ||
/> | ||
</Breadcrumbs.Item> | ||
</Breadcrumbs> | ||
) | ||
|
||
export const DynamicChildren = () => { | ||
const [items, setItems] = useState([ | ||
{id: 1, href: '#', name: 'Home'}, | ||
{id: 2, href: '#', name: 'Docs'}, | ||
{id: 3, href: '#', name: 'Components'}, | ||
]) | ||
|
||
const addItem = () => { | ||
const newId = Math.max(...items.map(item => item.id)) + 1 | ||
const names = ['Advanced', 'Examples', 'Guides', 'API', 'Tutorials', 'Reference'] | ||
const randomName = names[Math.floor(Math.random() * names.length)] | ||
setItems([...items, {id: newId, href: '#', name: `${randomName}-${newId}`}]) | ||
} | ||
|
||
const removeItem = () => { | ||
if (items.length > 1) { | ||
setItems(items.slice(0, -1)) | ||
} | ||
} | ||
|
||
const addMultipleItems = () => { | ||
const newItems = [ | ||
{id: Date.now() + 1, href: '#', name: 'Category'}, | ||
{id: Date.now() + 2, href: '#', name: 'Subcategory'}, | ||
{id: Date.now() + 3, href: '#', name: 'Item'}, | ||
{id: Date.now() + 4, href: '#', name: 'Details'}, | ||
{id: Date.now() + 5, href: '#', name: 'Specifications'}, | ||
] | ||
setItems([...items, ...newItems]) | ||
} | ||
|
||
const reset = () => { | ||
setItems([ | ||
{id: 1, href: '#', name: 'Home'}, | ||
{id: 2, href: '#', name: 'Docs'}, | ||
{id: 3, href: '#', name: 'Components'}, | ||
]) | ||
} | ||
|
||
return ( | ||
<div style={{display: 'flex', flexDirection: 'column', gap: '16px'}}> | ||
<div style={{display: 'flex', gap: '8px', marginBottom: '16px'}}> | ||
<button type="button" onClick={addItem} style={{padding: '4px 8px'}}> | ||
Add Item | ||
</button> | ||
<button type="button" onClick={removeItem} style={{padding: '4px 8px'}}> | ||
Remove Item | ||
</button> | ||
<button type="button" onClick={addMultipleItems} style={{padding: '4px 8px'}}> | ||
Add Many Items | ||
</button> | ||
<button type="button" onClick={reset} style={{padding: '4px 8px'}}> | ||
Reset | ||
</button> | ||
</div> | ||
|
||
<div> | ||
<h4 id="dynamic-breadcrumbs-heading" style={{margin: '0 0 8px 0'}}> | ||
Dynamic breadcrumbs | ||
</h4> | ||
<Breadcrumbs overflow="menu-with-root"> | ||
{items.map((item, index) => ( | ||
<Breadcrumbs.Item key={item.id} href={item.href} selected={index === items.length - 1}> | ||
{item.name} | ||
</Breadcrumbs.Item> | ||
))} | ||
</Breadcrumbs> | ||
</div> | ||
|
||
<div style={{marginTop: '16px', fontSize: '12px'}}> | ||
Current items: {items.length} | Try adding/removing items to see how overflow behavior changes | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.BreadcrumbsBase { | ||
display: flex; | ||
justify-content: space-between; | ||
width: 100%; | ||
} | ||
|
||
.BreadcrumbsList { | ||
|
@@ -9,10 +10,100 @@ | |
margin-bottom: 0; | ||
} | ||
|
||
.ItemWrapper { | ||
[data-overflow='menu'] .BreadcrumbsList, | ||
[data-overflow='menu-with-root'] .BreadcrumbsList { | ||
white-space: nowrap; | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
|
||
.BreadcrumbsItem { | ||
display: inline-grid; | ||
grid-auto-flow: column; | ||
align-items: center; | ||
flex: 0 99999 auto; | ||
min-width: auto; | ||
font-size: var(--text-body-size-medium); | ||
white-space: nowrap; | ||
list-style: none; | ||
|
||
&:first-child { | ||
margin-left: 0; | ||
} | ||
|
||
&:last-child { | ||
.ItemSeparator { | ||
display: none; | ||
} | ||
} | ||
} | ||
|
||
[data-overflow='menu'] .Item, | ||
[data-overflow='menu-with-root'] .Item { | ||
display: inline-block; | ||
font-size: var(--text-body-size-medium); | ||
color: var(--fgColor-default); | ||
text-decoration: none; | ||
padding-inline: var(--base-size-6); | ||
padding-block: var(--base-size-4); | ||
border-radius: var(--borderRadius-medium); | ||
|
||
&:hover { | ||
background: var(--control-transparent-bgColor-hover); | ||
pksjce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
text-decoration: none; | ||
} | ||
|
||
&:focus { | ||
@mixin focusOutline; | ||
} | ||
} | ||
|
||
.MenuDetails { | ||
position: relative; | ||
display: inline-block; | ||
} | ||
|
||
summary { | ||
list-style: none; | ||
cursor: pointer; | ||
outline: none; | ||
} | ||
|
||
summary::-webkit-details-marker { | ||
display: none; | ||
} | ||
|
||
.MenuOverlay { | ||
position: absolute; | ||
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. We need to have an offset between the trigger and the menu, but I'm not sure how you want to implement that with this custom overlay. The variable for this is |
||
z-index: 1; | ||
box-shadow: var(--shadow-resting-small); | ||
border-radius: var(--borderRadius-large); | ||
background-color: var(--overlay-bgColor); | ||
list-style: none; | ||
min-width: var(--overlay-width-xsmall); | ||
max-height: 100vh; | ||
max-width: var(--overlay-width-small); | ||
overflow: hidden; | ||
} | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
.MenuOverlay { | ||
animation: overlay-appear 200ms cubic-bezier(0.33, 1, 0.68, 1); | ||
} | ||
} | ||
|
||
pksjce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.ItemSeparator { | ||
color: var(--fgColor-muted); | ||
display: flex; | ||
align-self: center; | ||
justify-content: center; | ||
white-space: nowrap; | ||
user-select: none; | ||
} | ||
|
||
.ItemWrapper { | ||
display: inline-block; | ||
font-size: var(--text-body-size-medium); | ||
list-style: none; | ||
|
||
&::after { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.