Repository navigation
feat(ui): add breadcrumbs UI to PluginHeader - #34587
Conversation
🎨 Visual Testing with Chromatic
|
db166d0 to
5614020
Compare
Signed-off-by: Claire Peng <[email protected]>
Signed-off-by: Claire Peng <[email protected]>
dc4642e to
29f00e1
Compare
|
Thanks for the contribution! |
fdf944c to
66b21c5
Compare
- passed via breadcrumbs prop - collapses middle segments if more than 5 segments - shows tooltip if text is truncated Signed-off-by: Claire Peng <[email protected]>
66b21c5 to
772a190
Compare
breadcrumbs prop & breadcrumbs to PluginHeader
| useIsomorphicLayoutEffect(() => { | ||
| const el = ref.current; | ||
| if (!el) return undefined; | ||
|
|
||
| const check = () => setTruncated(el.scrollWidth > el.clientWidth); | ||
|
|
||
| return observeResize(el, check); | ||
| }, []); |
There was a problem hiding this comment.
we don't reaaaally need this on PluginHeader breadcrumbs because the max-width is fixed, but I had this from the previous PR attempt and it might be useful for other text elements in the future
There was a problem hiding this comment.
Not sure I follow, wouldn't we need this to pick up changes where the window is resized? Or how would we do it without?
There was a problem hiding this comment.
For if a sibling component changed size and affected the amount of space that a current component's text has to occupy
Eg. being able to drag the sibling's width
Signed-off-by: Claire Peng <[email protected]>
| <RACBreadcrumb key="collapsed"> | ||
| <BreadcrumbTooltipWrapper label={ariaLabel} showTooltip> | ||
| <MenuTrigger> | ||
| <RACButton aria-label={ariaLabel} className={ellipsisClassName}> |
There was a problem hiding this comment.
Using this instead of BUI Button to prevent layout shift from the button's padding, when we go from uncollapse to collapsed
breadcrumbs prop & breadcrumbs to PluginHeaderPluginHeader
Naycon
left a comment
There was a problem hiding this comment.
Found a tooltip bug, and we may need to do something about the last segment overflowing.
| <Menu> | ||
| {items.map(item => ( | ||
| <MenuItem key={item.href} href={item.href}> | ||
| {item.label} | ||
| </MenuItem> | ||
| ))} | ||
| </Menu> | ||
| </MenuTrigger> | ||
| </BreadcrumbTooltipWrapper> |
There was a problem hiding this comment.
In addition to the trigger, we get tooltips on the menu items as well when hovered with the mouse. I wonder if it could be because we're wrapping the menu items in Tooltip as well.
There was a problem hiding this comment.
Yeah shall we just remove this tooltip? it's aria-labeled already and within Portal there's mix useage of icon buttons having tooltips vs. not
| icon?: React.ReactNode; | ||
| title?: string; | ||
| titleLink?: string; | ||
| breadcrumbs?: BreadcrumbEntry[]; |
There was a problem hiding this comment.
I think it'd make sense for this component to own it's own Breadcrumb shape, so I believe we should have this type defined here instead. Fine to duplicate and have two types, one for the hook and one here.
| const ref = useRef<T>(null); | ||
| const [truncated, setTruncated] = useState(false); | ||
|
|
||
| // Re-check after each render in case the content changes without a resize event. |
There was a problem hiding this comment.
if there were a sibling component that changed size, and that made our text start to truncate
| useIsomorphicLayoutEffect(() => { | ||
| const el = ref.current; | ||
| if (!el) return undefined; | ||
|
|
||
| const check = () => setTruncated(el.scrollWidth > el.clientWidth); | ||
|
|
||
| return observeResize(el, check); | ||
| }, []); |
There was a problem hiding this comment.
Not sure I follow, wouldn't we need this to pick up changes where the window is resized? Or how would we do it without?
- remove useBreadcrumbs hook - remove BreadcrumbEntry type - remove BreadcrumbsRegistration & BreadcrumbsRegistryProvider Signed-off-by: Claire Peng <[email protected]>
Signed-off-by: Claire Peng <[email protected]>
Changed Packages
|
Signed-off-by: Claire Peng <[email protected]>
07ac0fc to
26e411c
Compare
…focusable with tooltip if truncated Signed-off-by: Claire Peng <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds optional breadcrumbs support to PluginHeader in @backstage/ui, including truncation-aware tooltips and an ellipsis menu that collapses middle segments for longer trails.
Changes:
- Introduces
breadcrumbs?: PluginHeaderBreadcrumbEntry[]onPluginHeaderand exports the new public type. - Adds
PluginHeaderBreadcrumbscomponent with ellipsis collapse behavior and truncation tooltips (viauseIsTruncated). - Updates styling, Storybook stories, tests, API report, and includes a changeset.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/ui/src/components/PluginHeader/useIsTruncated.ts | New hook to detect truncation (with ResizeObserver + debounce). |
| packages/ui/src/components/PluginHeader/useIsTruncated.test.tsx | Unit tests for truncation detection and debounced resize behavior. |
| packages/ui/src/components/PluginHeader/types.ts | Adds breadcrumbs prop and new public breadcrumb entry type. |
| packages/ui/src/components/PluginHeader/PluginHeaderBreadcrumbs.tsx | New breadcrumbs UI, tooltip-on-truncation, and collapse-to-ellipsis logic. |
| packages/ui/src/components/PluginHeader/PluginHeaderBreadcrumbs.test.tsx | Tests for rendering, collapsing behavior, and tooltip behavior. |
| packages/ui/src/components/PluginHeader/PluginHeader.tsx | Renders breadcrumbs when provided and visually hides the title heading. |
| packages/ui/src/components/PluginHeader/PluginHeader.test.tsx | Tests for PluginHeader rendering, including breadcrumbs cases. |
| packages/ui/src/components/PluginHeader/PluginHeader.stories.tsx | Adds Storybook stories demonstrating breadcrumbs configurations. |
| packages/ui/src/components/PluginHeader/PluginHeader.module.css | Adds breadcrumbs styling + layout adjustments to support truncation/collapsing. |
| packages/ui/src/components/PluginHeader/index.tsx | Re-exports PluginHeaderBreadcrumbEntry. |
| packages/ui/src/components/PluginHeader/definition.ts | Adds classNames/propDefs entries for breadcrumbs styling hooks. |
| packages/ui/report.api.md | Updates API report for the new exported type and prop. |
| .changeset/great-states-smash.md | Changeset describing the new breadcrumbs prop behavior. |
| const { ref, truncated } = useIsTruncated<HTMLParagraphElement>(); | ||
|
|
||
| return ( | ||
| <BreadcrumbTooltipWrapper label={entry.label} showTooltip={truncated}> | ||
| <Focusable excludeFromTabOrder={!truncated}> | ||
| <Text | ||
| variant="body-medium" | ||
| truncate | ||
| ref={ref as React.Ref<HTMLParagraphElement>} | ||
| > |
There was a problem hiding this comment.
This causes a type-error when we do this, it's set in Text. I'm hesitant to change this as I don't know the context for why Text's ref type is HTMLParagraphElement instead of an enum that includes HTMLSpanElement
| } | ||
|
|
||
| return ( | ||
| <nav id="Breadcrumbs" className={className}> |
There was a problem hiding this comment.
Currently BUI design will not have multiple breadcrumbs throughout the app
There was a problem hiding this comment.
Maybe it's still useful to set a aria-label for the navigation landmark? I assume the id won't become the label automatically, or is that sufficient?
Signed-off-by: Claire Peng <[email protected]>
Naycon
left a comment
There was a problem hiding this comment.
Looks good! Some minor things to take a second look at, but I'll pre-approve because it's also shippable as-is. Thanks for adding this in Claire!
| These breadcrumbs: | ||
|
|
||
| - Collapses middle segments if 5 or more segments | ||
| - Shows tooltip if text is truncated |
There was a problem hiding this comment.
Should have an affected components string here, like so:
| - Shows tooltip if text is truncated | |
| - Shows tooltip if text is truncated | |
| **Affected components:** PluginHeader |
| These breadcrumbs: | ||
|
|
||
| - Collapses middle segments if 5 or more segments | ||
| - Shows tooltip if text is truncated |
There was a problem hiding this comment.
Should have an affected components string here, like so:
| - Shows tooltip if text is truncated | |
| - Shows tooltip if text is truncated | |
| **Affected components:** PluginHeader |
| standalone | ||
| variant="body-medium" | ||
| truncate | ||
| ref={ref as React.Ref<HTMLAnchorElement>} |
There was a problem hiding this comment.
Could this cast be avoided by explicitly typing the return value of useIsTrucnated?
| } | ||
|
|
||
| return ( | ||
| <nav id="Breadcrumbs" className={className}> |
There was a problem hiding this comment.
Maybe it's still useful to set a aria-label for the navigation landmark? I assume the id won't become the label automatically, or is that sufficient?
Signed-off-by: Claire Peng <[email protected]>
| const { ref, truncated } = useIsTruncated<HTMLParagraphElement>(); | ||
|
|
||
| return ( | ||
| <BreadcrumbTooltipWrapper label={entry.label} showTooltip={truncated}> | ||
| <Focusable excludeFromTabOrder={!truncated}> | ||
| <Text variant="body-medium" truncate ref={ref}> | ||
| {entry.label} | ||
| </Text> |
| } | ||
|
|
||
| return ( | ||
| <nav id="Breadcrumbs" aria-label="Breadcrumbs" className={className}> |
Signed-off-by: Claire Peng <[email protected]>
|
Thank you for contributing to Backstage! The changes in this pull request will be part of the |
Hey, I just made a Pull Request!
Screen.Recording.2026-06-14.at.15.48.24.mov
PluginHeader✔️ Checklist
Signed-off-byline in the message. (more info)