Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/fast-pugs-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Breadcrumbs: On narrow viewports, only show the current page breadcrumb and the overflow menu when `overflow="menu"` is set.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if this should be the default 🤔

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions e2e/components/Breadcrumbs.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {test, expect} from '@playwright/test'
import {visit} from '../test-helpers/storybook'
import {themes} from '../test-helpers/themes'
import {viewports} from '../test-helpers/viewports'

const stories = [
{
Expand Down Expand Up @@ -37,4 +38,44 @@ test.describe('Breadcrumbs', () => {
}
})
}

test.describe('Overflow Menu', () => {
test('narrow viewport @vrt', async ({page}) => {
await visit(page, {
id: 'components-breadcrumbs-features--overflow-menu',
globals: {
colorScheme: 'light',
},
})

await page.setViewportSize({width: viewports['primer.breakpoint.xs'] - 1, height: 768})
await expect(page).toHaveScreenshot('Breadcrumbs.OverflowMenu.narrow.png')
})

test('wide viewport @vrt', async ({page}) => {
await visit(page, {
id: 'components-breadcrumbs-features--overflow-menu',
globals: {
colorScheme: 'light',
},
})

await page.setViewportSize({width: viewports['primer.breakpoint.md'], height: 768})
await expect(page).toHaveScreenshot('Breadcrumbs.OverflowMenu.wide.png')
})
})

test.describe('Overflow Menu With Root', () => {
test('narrow viewport @vrt', async ({page}) => {
await visit(page, {
id: 'components-breadcrumbs-features--overflow-menu-with-root',
globals: {
colorScheme: 'light',
},
})

await page.setViewportSize({width: viewports['primer.breakpoint.xs'] - 1, height: 768})
await expect(page).toHaveScreenshot('Breadcrumbs.OverflowMenuWithRoot.narrow.png')
})
})
})
4 changes: 3 additions & 1 deletion packages/react/src/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ function Breadcrumbs({className, children, style, overflow = 'wrap', variant = '
(availableWidth: number) => {
let eHideRoot = effectiveHideRoot
const MENU_BUTTON_WIDTH = menuButtonWidth
const MIN_VISIBLE_ITEMS = !eHideRoot ? 3 : 4
const NARROW_BREAKPOINT = 544
const isNarrow = availableWidth < NARROW_BREAKPOINT
Comment on lines +192 to +193
const MIN_VISIBLE_ITEMS = isNarrow && eHideRoot ? 1 : !eHideRoot ? 3 : 4
Comment on lines +192 to +194
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I feel like these double ternaries are hard to read. I'd split this into multiple lines or a function


const calculateVisibleItemsWidth = (w: number[]) => {
const widths = w.reduce((sum, width) => sum + width + 16, 0)
Expand Down
Loading