Skip to content

UI: Fix mobile navigation when renderLabel returns a React node#34262

Merged
JReinhold merged 3 commits into
storybookjs:nextfrom
Dev-profil:fix/mobile-renderLabel-react-node
Mar 27, 2026
Merged

UI: Fix mobile navigation when renderLabel returns a React node#34262
JReinhold merged 3 commits into
storybookjs:nextfrom
Dev-profil:fix/mobile-renderLabel-react-node

Conversation

@Dev-profil
Copy link
Copy Markdown
Contributor

@Dev-profil Dev-profil commented Mar 22, 2026

Summary

Fixes #34261

When sidebar.renderLabel returns a React node (supported on desktop sidebar), the mobile bottom bar built a breadcrumb string via template literals, coercing nodes to [object Object].

Changes

  • In useFullStoryName, use renderLabel output only when it is a string; otherwise fall back to name for the current story and each parent in the path.
  • Add story ReactNodeRenderLabel to cover non-string renderLabel (regression guard for Chromatic / manual QA).

How to test

  1. Run Storybook for the core manager UI (or open Mobile/NavigationReactNodeRenderLabel in the internal Storybook).
  2. Confirm the bottom bar shows component/story (plain names), not [object Object].

Notes for reviewers

  • Deliberately minimal: mobile bar is text-only; mirroring rich React labels would need a larger UI change. This aligns with fixing the broken string coercion while keeping ellipsis behavior on plain names.

Summary by CodeRabbit

Bug Fixes

  • Enhanced mobile navigation to more robustly handle custom label rendering when non-string values are returned, improving stability and preventing potential display issues.

Tests

  • Added test story demonstrating ReactNode-based custom label rendering for mobile navigation.

@Dev-profil Dev-profil changed the base branch from main to next March 22, 2026 19:29
@Dev-profil Dev-profil force-pushed the fix/mobile-renderLabel-react-node branch from 6fcb64a to 2cd0cf2 Compare March 22, 2026 19:29
When renderLabel returns a React node instead of a string, the mobile navigation bottom bar displays [object Object] due to template literal string coercion. This checks the return type and falls back to .name when the result is not a string, matching the behavior the user expects.

Closes #34261
@Dev-profil Dev-profil force-pushed the fix/mobile-renderLabel-react-node branch from 2cd0cf2 to d7f47f6 Compare March 22, 2026 19:32
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d0ddbc24-633c-4ff6-9980-e35fb5d47374

📥 Commits

Reviewing files that changed from the base of the PR and between 87733f1 and d7f47f6.

📒 Files selected for processing (2)
  • code/core/src/manager/components/mobile/navigation/MobileNavigation.stories.tsx
  • code/core/src/manager/components/mobile/navigation/MobileNavigation.tsx

📝 Walkthrough

Walkthrough

This PR extends MobileNavigation's renderLabel support to handle ReactNode return types alongside strings. A new Story export (ReactNodeRenderLabel) demonstrates this capability with a mock store defining renderLabel as a function returning a styled ReactNode. The corresponding component hook is updated to strictly validate that renderLabel returns a string before using it as a label, falling back to the story or node name otherwise.

Changes

Cohort / File(s) Summary
MobileNavigation Story
code/core/src/manager/components/mobile/navigation/MobileNavigation.stories.tsx
Added new ReactNodeRenderLabel Story export with ManagerContext decorator providing a mock store where renderLabel returns a styled ReactNode (<em>{startCase(name)}</em>) for all tree nodes.
MobileNavigation Hook Update
code/core/src/manager/components/mobile/navigation/MobileNavigation.tsx
Updated useFullStoryName to validate renderLabel results as strings using typeof checks before using them; falls back to currentStory.name or node.name when renderLabel returns non-string values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • storybookjs/storybook#32577: Modifies mockManagerStore and renderLabel behavior in MobileNavigation.stories.tsx with similar concerns around renderLabel type handling.

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.

Tip

You can disable sequence diagrams in the walkthrough.

Disable the reviews.sequence_diagrams setting to disable sequence diagrams in the walkthrough.

Copy link
Copy Markdown
Contributor

@JReinhold JReinhold left a comment

Choose a reason for hiding this comment

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

Thanks ❤️

@JReinhold JReinhold merged commit 6d4fcb5 into storybookjs:next Mar 27, 2026
117 of 118 checks passed
@github-project-automation github-project-automation Bot moved this from Empathy Queue (prioritized) to Done in Core Team Projects Mar 27, 2026
@github-actions github-actions Bot mentioned this pull request Mar 27, 2026
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: renderLabel only handles strings in mobile mode

4 participants