Repository navigation
UI: Add renderAriaLabel and a context argument to renderLabel - #36218
Conversation
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 74 | 74 | 0 |
| Self size | 21.67 MB | 21.63 MB | 🎉 -38 KB 🎉 |
| Dependency size | 31.22 MB | 31.22 MB | 0 B |
| Bundle Size Analyzer | Link | Link |
@storybook/nextjs
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 447 | 536 | 🚨 +89 🚨 |
| Self size | 641 KB | 640 KB | 🎉 -682 B 🎉 |
| Dependency size | 61.23 MB | 64.97 MB | 🚨 +3.74 MB 🚨 |
| Bundle Size Analyzer | Link | Link |
@storybook/cli
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 180 | 180 | 0 |
| Self size | 883 KB | 883 KB | 🎉 -90 B 🎉 |
| Dependency size | 86.81 MB | 86.77 MB | 🎉 -38 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/codemod
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 173 | 173 | 0 |
| Self size | 44 KB | 44 KB | 0 B |
| Dependency size | 85.29 MB | 85.25 MB | 🎉 -38 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
create-storybook
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 75 | 75 | 0 |
| Self size | 1.07 MB | 1.07 MB | 0 B |
| Dependency size | 52.89 MB | 52.85 MB | 🎉 -38 KB 🎉 |
| Bundle Size Analyzer | node | node |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Essentials Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. WalkthroughThe sidebar API now supports ChangesSidebar label rendering
Sequence Diagram(s)sequenceDiagram
participant MobileNavigation
participant SidebarCallbacks
participant MobileBottomBarContent
MobileNavigation->>SidebarCallbacks: Render label with bottom-bar context
SidebarCallbacks-->>MobileNavigation: Return visible and ARIA labels
MobileNavigation->>MobileBottomBarContent: Pass visible name and full ARIA label
MobileBottomBarContent->>MobileBottomBarContent: Announce current page with ARIA label
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The documented sidebar label and announcement changes are consistent, with no remaining merge-blocking risk. Comment |
861da80 to
b17fd82
Compare
Custom sidebar labels get two additions to the manager API. renderLabel
receives a third context argument, { isMobile, location }, so a label can
adapt to where it renders - the sidebar tree versus the mobile bottom
bar, whose labels are best stripped of contextual UI. The parameter is
typed optional, so pre-existing consumers that invoke the callback with
two arguments keep compiling, while Storybook itself always passes it.
renderAriaLabel lands alongside as the accessible counterpart: it must
return a plain string and feeds accessible names for entries and the
bottom bar's current-page announcement. Both callbacks are stamped onto
every entry the story hash builds, sharing the API_SidebarOptions types
so the config and entry surfaces cannot drift.
The mobile bottom bar concatenates names into plain strings for its
visible label and its screen-reader announcement alike, so a renderLabel
that returns a React element (the long-documented pattern) now falls
back to the entry name rather than stringifying to [object Object] - and
the announcement uses the aria chain rather than the visible one. Merging
every ref index also moves behind a memo: it allocates an object as large
as the whole sidebar and ran on every state-driven re-render.
TestEntry's parent becomes required while here: a test entry is always
nested under its story, and the optionality inherited from stories only
forced needless narrowing.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WSk2g5RrcpxacMMUTRv9HK
b17fd82 to
7c77dfc
Compare
The docs table and prose describe renderAriaLabel but the snippet only demonstrated renderLabel. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WSk2g5RrcpxacMMUTRv9HK
Stack PRs #36216, #36218, and #36219 landed on next, so most conflicts were this branch's evolved copies of their files; kept this branch's wording and architecture (one scroll area, per-row indent lines) and carried over next's additions: the @react-aria/focus dependency, the ShowChangesButton below the search field, Modal's Escape stopPropagation, and the 11.0 migration entries. ShowChangesButton's icon maps to this branch's renamed change-modified symbol, and the migration section for the sidebar rewrite now only lists what next does not already document. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WSk2g5RrcpxacMMUTRv9HK
Closes #
What I did
Part of the Sidebar 2.0 stack (#33422): extends the sidebar label-rendering API so labels can adapt to where they render and expose proper accessible names.
sidebar.renderLabelreceives a thirdcontextargument:{ isMobile: boolean; location: 'sidebar' | 'bottom-bar' }. The parameter is typed optional, so existing two-argument consumers keep compiling; Storybook itself always passes it.sidebar.renderAriaLabeloption: the accessible counterpart, which must return a plain string. It feeds accessible names for entries and the mobile bottom bar's current-page announcement. Both callbacks are stamped onto every entry in the story hash and share theAPI_SidebarOptionstypes so the config and entry surfaces can't drift.renderLabelreturning a React element (the long-documented pattern) now falls back to the entry name instead of stringifying to[object Object]— and the announcement uses the aria chain. Merging every ref index moves behind a memo (it allocates an object as large as the whole sidebar and ran on every state-driven re-render).API_TestEntry.parentbecomes required: a test entry is always nested under its story.features-and-behavior.mdx, the manager snippet, and a MIGRATION entry.The new sidebar tree (#33422) consumes the same context for its rows; this PR wires the mobile bottom bar and the API surface so that consumption is a drop-in.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Caution
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
cd code && yarn storybook:ui— the internalmanager.tsxconfig now sets bothrenderLabelandrenderAriaLabel.renderAriaLabel("<type> <name>") while the visible label followsrenderLabel.sb-sr-onlyspan).Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsDeclare whether manual QA will be needed for this PR during the next release, through
qa:neededorqa:skipMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🤖 Generated with Claude Code
https://claude.ai/code/session_01WSk2g5RrcpxacMMUTRv9HK
Generated by Claude Code