Skip to content

fix (Breadcrumb): ref not forwarded for trigger#694

Open
paanSinghCoder wants to merge 3 commits intomainfrom
fix/breadcrumb-ref-not-forwarded
Open

fix (Breadcrumb): ref not forwarded for trigger#694
paanSinghCoder wants to merge 3 commits intomainfrom
fix/breadcrumb-ref-not-forwarded

Conversation

@paanSinghCoder
Copy link
Contributor

@paanSinghCoder paanSinghCoder commented Mar 11, 2026

Description

fix: Forward ref when BreadcrumbItem uses dropdown
fix: Props silently ignored in dropdown path

When BreadcrumbItem is used with dropdownItems, the forwarded ref and other props was never attached and was effectively dropped. The ref and other props are now passed through to Menu.Trigger, so callers can attach a ref to the same interactive element in both link and dropdown variants.

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?

Manual

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

Summary by CodeRabbit

Release Notes

  • Refactor
    • Improved internal handling of breadcrumb dropdown triggers (better ref and prop handling, and consolidated styling).
    • No changes to public API or user-facing behavior.

@paanSinghCoder paanSinghCoder self-assigned this Mar 11, 2026
@vercel
Copy link

vercel bot commented Mar 11, 2026

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

Project Deployment Actions Updated (UTC)
apsara Ready Ready Preview, Comment Mar 12, 2026 8:48am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

📝 Walkthrough

Walkthrough

BreadcrumbItem now forwards a ref to the dropdown trigger (as HTMLButtonElement), composes and applies the trigger className, and spreads remaining button props (including id, title, and ARIA attributes) onto Menu.Trigger. Change is internal; public API and dropdown rendering logic unchanged.

Changes

Cohort / File(s) Summary
Breadcrumb Dropdown Ref & Prop Forwarding
packages/raystack/components/breadcrumb/breadcrumb-item.tsx
Menu.Trigger now receives a forwarded ref (cast to HTMLButtonElement), merges className with styles['breadcrumb-dropdown-trigger'], and spreads remaining props (e.g., id, title, aria-*) by casting to React.ButtonHTMLAttributes<HTMLButtonElement>. Public API unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Poem

🐰 A little ref hopped to the gate,
Button classes joined in state,
IDs and ARIA tucked in tight,
Breadcrumbs ready, poised for flight,
I nibble code and hum with delight. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically identifies the main fix: forwarding a ref to the breadcrumb trigger in the dropdown path, which matches the core change described in the PR summary.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 fix/breadcrumb-ref-not-forwarded

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/raystack/components/breadcrumb/breadcrumb-item.tsx`:
- Around line 58-61: The component declares the forwarded ref as
HTMLAnchorElement but sometimes forwards it to Menu.Trigger (an
HTMLButtonElement), causing a type mismatch; update the ref type on the
component (the forwarded ref symbol `ref`) to widen it to either
`HTMLAnchorElement | HTMLButtonElement` or `HTMLElement` so callers' refs remain
correct, and adjust the prop/forwardRef signature where `ref` is declared (the
forwardRef in breadcrumb-item.tsx) to use the chosen union/HTMLElement type and
update any local casts so the `Menu.Trigger` usage no longer force-casts `ref`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: adad8e04-c918-4548-baf2-9986ee0f80b1

📥 Commits

Reviewing files that changed from the base of the PR and between 14de0ba and 9c159ad.

📒 Files selected for processing (1)
  • packages/raystack/components/breadcrumb/breadcrumb-item.tsx

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/raystack/components/breadcrumb/breadcrumb-item.tsx (1)

55-82: ⚠️ Potential issue | 🔴 Critical

Dropdown path must wrap in <li> element to maintain valid list semantics.

The non-dropdown path wraps content in <li className={...}> but the dropdown path returns <Menu> directly. Since the parent BreadcrumbRoot renders <ol> and expects <li> children, the dropdown path violates semantic HTML. This produces invalid DOM structure (<ol><Menu>...</Menu></ol>) and breaks accessibility expectations for breadcrumb navigation.

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

In `@packages/raystack/components/breadcrumb/breadcrumb-item.tsx` around lines 55
- 82, The dropdown branch in breadcrumb-item.tsx returns <Menu> directly which
breaks the parent <ol> semantics; wrap the existing Menu JSX inside the same <li
className={cx(styles['breadcrumb-item'], className)}> wrapper used by the
non-dropdown path so the component always renders an <li> child for
BreadcrumbRoot. Keep the same ref usage on Menu.Trigger, preserve id/title/aria
props and the dropdownItems mapping to Menu.Item, and ensure the className uses
styles['breadcrumb-item'] (or the same variable used in the non-dropdown branch)
so styling and semantics remain consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/raystack/components/breadcrumb/breadcrumb-item.tsx`:
- Around line 58-66: The dropdown branch only forwards specific props to
Menu.Trigger (id, title, aria-*) causing data-*, other ARIA attributes, and
event handlers to be dropped when dropdownItems is present; update the
Menu.Trigger call in breadcrumb-item.tsx (the dropdown path where Menu.Trigger
is rendered) to spread the remaining props (e.g., include ...props or a
filteredProps object) so that Menu.Trigger receives the same external attributes
and event handlers as the non-dropdown path (which uses ...props), ensuring
consistent prop forwarding for dropdownItems and non-dropdown variants.

---

Outside diff comments:
In `@packages/raystack/components/breadcrumb/breadcrumb-item.tsx`:
- Around line 55-82: The dropdown branch in breadcrumb-item.tsx returns <Menu>
directly which breaks the parent <ol> semantics; wrap the existing Menu JSX
inside the same <li className={cx(styles['breadcrumb-item'], className)}>
wrapper used by the non-dropdown path so the component always renders an <li>
child for BreadcrumbRoot. Keep the same ref usage on Menu.Trigger, preserve
id/title/aria props and the dropdownItems mapping to Menu.Item, and ensure the
className uses styles['breadcrumb-item'] (or the same variable used in the
non-dropdown branch) so styling and semantics remain consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 08e69747-c14b-4753-b829-bd9a6e0332e2

📥 Commits

Reviewing files that changed from the base of the PR and between 9c159ad and c6e9277.

📒 Files selected for processing (1)
  • packages/raystack/components/breadcrumb/breadcrumb-item.tsx

@paanSinghCoder paanSinghCoder changed the title fix (breadcrumb): ref not forwarded for trigger fix (Breadcrumb): ref not forwarded for trigger Mar 12, 2026
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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/raystack/components/breadcrumb/breadcrumb-item.tsx`:
- Around line 58-61: The public ref type for BreadcrumbItem is incorrect because
BreadcrumbItem is declared as forwardRef<HTMLAnchorElement, ...> but when
dropdownItems is present you pass that ref into Menu.Trigger (an
HTMLButtonElement) via ref; change the component's ref type to accurately
reflect both render paths—replace forwardRef<HTMLAnchorElement, ...> with a
widened ref type such as forwardRef<HTMLAnchorElement | HTMLButtonElement,
Props> or use a generic HTMLElement/Element ref (React.Ref<HTMLAnchorElement |
HTMLButtonElement> or React.Ref<HTMLElement>) so callers get the correct element
type, and update any related prop/ref typings and exports (e.g., BreadcrumbItem,
Menu.Trigger usage, and the props interface) to avoid casting the ref with "as".

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3d86560a-642e-4661-9486-862b1bbc2279

📥 Commits

Reviewing files that changed from the base of the PR and between c6e9277 and 7df155f.

📒 Files selected for processing (1)
  • packages/raystack/components/breadcrumb/breadcrumb-item.tsx

Comment on lines +58 to +61
<Menu.Trigger
ref={ref as React.Ref<HTMLButtonElement>}
className={cx(styles['breadcrumb-dropdown-trigger'], className)}
{...(props as React.ButtonHTMLAttributes<HTMLButtonElement>)}
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 | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "BreadcrumbItem signature and dropdown ref cast:"
sed -n '20,65p' packages/raystack/components/breadcrumb/breadcrumb-item.tsx

echo
echo "Menu.Trigger definition and forwarded ref target:"
rg -n -C3 'forwardRef<|Trigger' packages/raystack/components/menu

Repository: raystack/apsara

Length of output: 16283


Don't cast the public anchor ref to a button ref.

Line 59 keeps BreadcrumbItem publicly typed as forwardRef<HTMLAnchorElement>, but the dropdown path now writes that ref into Menu.Trigger as HTMLButtonElement. A caller with useRef<HTMLAnchorElement>() will receive a button when dropdownItems is set, so the exported type is now lying. Widen or split the ref type so it matches the rendered element instead of hiding the mismatch with a cast.

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

In `@packages/raystack/components/breadcrumb/breadcrumb-item.tsx` around lines 58
- 61, The public ref type for BreadcrumbItem is incorrect because BreadcrumbItem
is declared as forwardRef<HTMLAnchorElement, ...> but when dropdownItems is
present you pass that ref into Menu.Trigger (an HTMLButtonElement) via ref;
change the component's ref type to accurately reflect both render paths—replace
forwardRef<HTMLAnchorElement, ...> with a widened ref type such as
forwardRef<HTMLAnchorElement | HTMLButtonElement, Props> or use a generic
HTMLElement/Element ref (React.Ref<HTMLAnchorElement | HTMLButtonElement> or
React.Ref<HTMLElement>) so callers get the correct element type, and update any
related prop/ref typings and exports (e.g., BreadcrumbItem, Menu.Trigger usage,
and the props interface) to avoid casting the ref with "as".

<Menu.Trigger
ref={ref as React.Ref<HTMLButtonElement>}
className={cx(styles['breadcrumb-dropdown-trigger'], className)}
{...(props as React.ButtonHTMLAttributes<HTMLButtonElement>)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not pass AnchorElement props to MenuTrigger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants