Skip to content

feat (1-breadcrumb): add automatic ellipsis support and hide items#667

Open
paanSinghCoder wants to merge 1 commit intomainfrom
feat/breadcrumb-auto-ellipsis
Open

feat (1-breadcrumb): add automatic ellipsis support and hide items#667
paanSinghCoder wants to merge 1 commit intomainfrom
feat/breadcrumb-auto-ellipsis

Conversation

@paanSinghCoder
Copy link
Contributor

@paanSinghCoder paanSinghCoder commented Mar 5, 2026

Breadcrumb 1st PR

Issue-600

Description

New props (root)

  • maxItems – Maximum number of breadcrumb items to show. When there are more items, the trail collapses: a fixed number at the start, ellipsis, then the rest at the end. At least 2 items are always visible (1 before and 1 after the ellipsis). Values < 2 are treated as 2.
  • itemsBeforeCollapse – Number of items to show before the ellipsis when collapsed. If not set, it is derived from maxItems (e.g. maxItems={5} → 2 before, 3 after). The count after the ellipsis is always derived.

Docs updates

  • README, JSDoc, and www breadcrumb docs updated to describe auto-collapse, maxItems, and itemsBeforeCollapse.
  • New examples: manual ellipsis, auto-collapse with maxItems, and itemsBeforeCollapse with more items to show collapse.
  • Props tables and copy updated (e.g. Item className, note on current prop, size example with tabs).

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional changes, no bug fixes just code improvements)
  • Chore (changes to the build process or auxiliary tools and libraries such as documentation generation)
  • Style (changes that do not affect the meaning of the code (white-space, formatting, etc))
  • Test (adding missing tests or correcting existing tests)
  • Improvement (Improvements to existing code)
  • Other (please specify)

How Has This Been Tested?

[Describe the tests that you ran to verify your changes]

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (.mdx files)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Screenshots (if appropriate):

[Add screenshots here]

Related Issues

[Link any related issues here using #issue-number]

Summary by CodeRabbit

  • New Features

    • Breadcrumb component now automatically collapses long navigation trails with configurable collapse points and item visibility controls.
    • Added size variations for breadcrumb display.
  • Documentation

    • Added comprehensive examples and documentation sections detailing breadcrumb configuration options and collapsing behavior.

@vercel
Copy link

vercel bot commented Mar 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
apsara Ready Ready Preview, Comment Mar 5, 2026 0:46am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

📝 Walkthrough

Walkthrough

The changes introduce an auto-collapse feature to the Breadcrumb component with new maxItems and itemsBeforeCollapse props, enabling dynamic truncation of breadcrumb items. Updates include comprehensive test coverage, documentation, demo code examples, and example page showcases across the component library and documentation site.

Changes

Cohort / File(s) Summary
Core Implementation
packages/raystack/components/breadcrumb/breadcrumb-root.tsx, apps/www/src/content/docs/components/breadcrumb/props.ts
Implements auto-collapse mechanism with fragment flattening, child parsing utilities, and computed content assembly. Adds maxItems and itemsBeforeCollapse props to control collapsing behavior, plus className prop to BreadcrumbItem.
Test Coverage
packages/raystack/components/breadcrumb/__tests__/breadcrumb.test.tsx
Comprehensive test suite for auto-collapse feature covering item visibility at various maxItems values, itemsBeforeCollapse constraints, edge cases (negative values, min items), Fragment children, and backward compatibility.
Documentation & Examples
apps/www/src/app/examples/page.tsx, apps/www/src/content/docs/components/breadcrumb/index.mdx, apps/www/src/content/docs/components/breadcrumb/demo.ts
Adds breadcrumb example section to examples page, expands documentation with new "Auto-collapse" and "itemsBeforeCollapse" sections, refactors sizeDemo to use tabs structure, and introduces maxItemsDemo and itemsBeforeCollapseDemo code blocks.
Demo Updates
apps/www/src/components/demo/demo.tsx
Adds three icon imports (BellIcon, FilterIcon, ShoppingBagFilledIcon) to demo scope for availability in demonstrations.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related issues

Suggested labels

Do not merge

Suggested reviewers

  • rsbh
  • rohilsurana

Poem

🐰 Hops with glee through breadcrumbs so fine,
Collapsing long trails with maxItems design,
Ellipsis bloom bright where the paths intertwine,
A rabbit's delight—now navigation will shine! ✨🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding automatic ellipsis support and item hiding to the Breadcrumb component.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/breadcrumb-auto-ellipsis

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/raystack/components/breadcrumb/breadcrumb-root.tsx (3)

148-166: keyed helper redundantly checks isValidElement.

The keyed function is only ever called with elements from beforeItems and afterItems, which are already validated as ReactElement instances from parseBreadcrumbChildren. The isValidElement(el) check is unnecessary.

♻️ Optional simplification
-        const keyed = (el: ReactElement, k: string) =>
-          isValidElement(el) && el.key != null
-            ? el
-            : cloneElement(el, { key: k });
+        const keyed = (el: ReactElement, k: string) =>
+          el.key != null ? el : cloneElement(el, { key: k });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/raystack/components/breadcrumb/breadcrumb-root.tsx` around lines 148
- 166, The keyed helper unnecessarily calls isValidElement; since
beforeItems/afterItems are already ReactElement instances from
parseBreadcrumbChildren, remove the isValidElement check in the keyed function
(breadcrumb-root.tsx) and simply return the element if el.key != null, otherwise
return cloneElement(el, { key: k }); Update the keyed helper used where
beforeItems/afterItems are iterated so it only checks el.key and clones when
missing, keeping cloneElement usage and keys (e.g., calls in the
beforeItems.forEach and afterItems.forEach loops) intact.

69-88: Consider handling unrecognized children gracefully.

The parseBreadcrumbChildren function silently drops children that don't match known breadcrumb parts (Item, Separator, Ellipsis). This could lead to confusion if users pass custom elements or text nodes. Consider either logging a warning in development or documenting this behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/raystack/components/breadcrumb/breadcrumb-root.tsx` around lines 69
- 88, parseBreadcrumbChildren currently drops children that aren't recognized
breadcrumb parts (BreadcrumbItem, BreadcrumbSeparator, BreadcrumbEllipsis) with
no feedback; update parseBreadcrumbChildren to warn in development when an
element is a valid React element but not matched by isBreadcrumbPart (and
optionally when a non-empty text node or unknown node is passed) by calling
console.warn or process.env.NODE_ENV check inside the flat.forEach loop;
reference the existing symbols parseBreadcrumbChildren,
flattenFragments(Children.toArray(children)), isValidElement, isBreadcrumbPart,
BreadcrumbItem, BreadcrumbSeparator, and BreadcrumbEllipsis and emit a clear
dev-only warning that includes the offending child/type so users know why their
node was dropped.

171-173: Unused _propsChildren extraction appears defensive but unnecessary.

The destructuring on line 171-173 extracts children from props to avoid passing it twice to the nav. However, children was already destructured at line 116, so it shouldn't be in props. This suggests the typing could be tightened, but it's harmless as written.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/raystack/components/breadcrumb/breadcrumb-root.tsx` around lines 171
- 173, The extraction of children into _propsChildren from props (const {
children: _propsChildren, ...restProps } = props) is redundant because children
is already destructured earlier; remove that destructuring and ensure you use
the existing children variable and a restProps that does not re-extract children
(or tighten the prop typing to exclude children from props) so children is not
handled twice in BreadcrumbRoot; update references to use restProps (or a
propsWithoutChildren alias) accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/www/src/app/examples/page.tsx`:
- Around line 61-66: The Breadcrumb.Item for the "Footwear" label has the wrong
href; update the href on the Breadcrumb.Item (the JSX element with label
"Footwear") to the correct path (e.g. change
'/products/electronics/laptops/gaming/accessories' to
'/products/electronics/laptops/gaming/accessories/footwear') so the link matches
the label.

---

Nitpick comments:
In `@packages/raystack/components/breadcrumb/breadcrumb-root.tsx`:
- Around line 148-166: The keyed helper unnecessarily calls isValidElement;
since beforeItems/afterItems are already ReactElement instances from
parseBreadcrumbChildren, remove the isValidElement check in the keyed function
(breadcrumb-root.tsx) and simply return the element if el.key != null, otherwise
return cloneElement(el, { key: k }); Update the keyed helper used where
beforeItems/afterItems are iterated so it only checks el.key and clones when
missing, keeping cloneElement usage and keys (e.g., calls in the
beforeItems.forEach and afterItems.forEach loops) intact.
- Around line 69-88: parseBreadcrumbChildren currently drops children that
aren't recognized breadcrumb parts (BreadcrumbItem, BreadcrumbSeparator,
BreadcrumbEllipsis) with no feedback; update parseBreadcrumbChildren to warn in
development when an element is a valid React element but not matched by
isBreadcrumbPart (and optionally when a non-empty text node or unknown node is
passed) by calling console.warn or process.env.NODE_ENV check inside the
flat.forEach loop; reference the existing symbols parseBreadcrumbChildren,
flattenFragments(Children.toArray(children)), isValidElement, isBreadcrumbPart,
BreadcrumbItem, BreadcrumbSeparator, and BreadcrumbEllipsis and emit a clear
dev-only warning that includes the offending child/type so users know why their
node was dropped.
- Around line 171-173: The extraction of children into _propsChildren from props
(const { children: _propsChildren, ...restProps } = props) is redundant because
children is already destructured earlier; remove that destructuring and ensure
you use the existing children variable and a restProps that does not re-extract
children (or tighten the prop typing to exclude children from props) so children
is not handled twice in BreadcrumbRoot; update references to use restProps (or a
propsWithoutChildren alias) accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 65b1ecac-7a92-4967-8461-a9e16b6675b4

📥 Commits

Reviewing files that changed from the base of the PR and between 1301b55 and 1aa6c11.

📒 Files selected for processing (7)
  • apps/www/src/app/examples/page.tsx
  • apps/www/src/components/demo/demo.tsx
  • apps/www/src/content/docs/components/breadcrumb/demo.ts
  • apps/www/src/content/docs/components/breadcrumb/index.mdx
  • apps/www/src/content/docs/components/breadcrumb/props.ts
  • packages/raystack/components/breadcrumb/__tests__/breadcrumb.test.tsx
  • packages/raystack/components/breadcrumb/breadcrumb-root.tsx

Comment on lines +61 to +66
<Breadcrumb.Item
href='/products/electronics/laptops/gaming/accessories'
current
>
Footwear
</Breadcrumb.Item>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Inconsistent href for "Footwear" item.

The href for "Footwear" is /products/electronics/laptops/gaming/accessories but the label is "Footwear". This appears to be a copy-paste error—the href should likely be /products/electronics/laptops/gaming/accessories/footwear or similar.

🐛 Suggested fix
     <Breadcrumb.Item
-      href='/products/electronics/laptops/gaming/accessories'
+      href='/products/electronics/laptops/gaming/accessories/footwear'
       current
     >
       Footwear
     </Breadcrumb.Item>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<Breadcrumb.Item
href='/products/electronics/laptops/gaming/accessories'
current
>
Footwear
</Breadcrumb.Item>
<Breadcrumb.Item
href='/products/electronics/laptops/gaming/accessories/footwear'
current
>
Footwear
</Breadcrumb.Item>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/www/src/app/examples/page.tsx` around lines 61 - 66, The Breadcrumb.Item
for the "Footwear" label has the wrong href; update the href on the
Breadcrumb.Item (the JSX element with label "Footwear") to the correct path
(e.g. change '/products/electronics/laptops/gaming/accessories' to
'/products/electronics/laptops/gaming/accessories/footwear') so the link matches
the label.

@paanSinghCoder paanSinghCoder self-assigned this Mar 5, 2026
@paanSinghCoder paanSinghCoder changed the title feat (breadcrumb): add automatic ellipsis support and hide items feat (breadcrumb-1): add automatic ellipsis support and hide items Mar 5, 2026
@paanSinghCoder paanSinghCoder changed the title feat (breadcrumb-1): add automatic ellipsis support and hide items feat (1-breadcrumb): add automatic ellipsis support and hide items Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant