Skip to content

Conversation

@ia319
Copy link
Member

@ia319 ia319 commented Dec 5, 2025

Closes #33281

What I did

  • Add showSelectedLabel prop to Select (default true).
  • Only show the selected label when this prop is enabled.
  • Set showSelectedLabel={false} in ToolbarMenuSelect.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make 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.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • New Features
    • Added a configurable option to control whether a select control shows the selected item's label (on by default).
    • Updated toolbar select behavior to optionally hide the selected label for a cleaner toolbar appearance.

✏️ Tip: You can customize this high-level summary in your review settings.

@ia319 ia319 added the ci:normal label Dec 5, 2025
@nx-cloud
Copy link

nx-cloud bot commented Dec 5, 2025

View your CI Pipeline Execution ↗ for commit b6ac5b3

Command Status Duration Result
nx run-many -t check --parallel=7 ✅ Succeeded 4m 58s View ↗
nx run-many -t compile --parallel=3 ✅ Succeeded 52s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-06 11:41:58 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 5, 2025

📝 Walkthrough

Walkthrough

Adds an optional showSelectedLabel?: boolean prop to Select (default true) to control whether a single-select shows the selected option's title; ToolbarMenuSelect now forwards showSelectedLabel (tied to its dynamicTitle flag) instead of computing a dynamic title internally.

Changes

Cohort / File(s) Summary
Select component
code/core/src/components/components/Select/Select.tsx
Added showSelectedLabel?: boolean to SelectProps, default-initialized to true in props destructuring, and updated single-select rendering to use `(showSelectedLabel && selectedOptions[0]?.title)
ToolbarMenuSelect usage
code/core/src/toolbar/components/ToolbarMenuSelect.tsx
Removed internal dynamic title computation and getSelectedTitle import; made title immutable (const), retained icon handling, and passed showSelectedLabel={dynamicTitle} to the Select instance.
Manifest
package.json
Present in diff listing (no code-level changes described).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Focus areas for review:
    • Type and defaulting of showSelectedLabel in SelectProps and props destructuring.
    • Single-select rendering logic when no selection exists or when children should be used as fallback.
    • ToolbarMenuSelect behavior when dynamicTitle is false/true (icon + label expectations).

Possibly related PRs

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6e1cae0 and b6ac5b3.

📒 Files selected for processing (1)
  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use ESLint and Prettier configurations that are enforced in the codebase

Files:

  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Enable TypeScript strict mode

Files:

  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
code/**/*.{ts,tsx,js,jsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{ts,tsx,js,jsx,mjs}: Use server-side logger from 'storybook/internal/node-logger' for Node.js code
Use client-side logger from 'storybook/internal/client-logger' for browser code
Do not use console.log, console.warn, or console.error directly unless in isolated files where importing loggers would significantly increase bundle size

Files:

  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
code/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Export functions that need to be tested from their modules

Files:

  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
code/**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{js,jsx,json,html,ts,tsx,mjs}: Run Prettier with --write flag to format code before committing
Run ESLint with yarn lint:js:cmd to check for linting issues and fix errors before committing

Files:

  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
🧠 Learnings (5)
📓 Common learnings
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/components/components/Tabs/Tabs.stories.tsx:222-227
Timestamp: 2025-11-05T09:36:55.944Z
Learning: Repo: storybookjs/storybook PR: 32458 — In code/core/src/components/components/Button/Button.tsx (React/TypeScript), ButtonProps includes ariaLabel?: string | false and the component maps it to the DOM aria-label. Convention: ariaLabel is mandatory on all Button usages — provide a descriptive string for icon-only buttons; set ariaLabel=false when the button’s children already serve as the accessible name. Do not suggest using a raw aria-label prop on Button call sites.
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/components/components/Select/Select.tsx:200-204
Timestamp: 2025-11-05T09:38:47.712Z
Learning: Repo: storybookjs/storybook — Guidance: Until Storybook 11 is released, do not suggest using React.useId anywhere (e.g., in code/core/src/components/components/Select/Select.tsx) to maintain compatibility with React 17 runtimes. Prefer advising: accept a caller-provided props.id and, if needed, generate a client-only fallback id to minimize SSR hydration issues — but avoid useId. Resume prompting for useId after Storybook 11.
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/manager/components/preview/Toolbar.tsx:102-105
Timestamp: 2025-10-03T07:55:42.639Z
Learning: In code/core/src/manager/components/preview/Toolbar.tsx, we intentionally do not add aria-label/aria-labelledby to StyledToolbar (AbstractToolbar) because the enclosing section is already labeled via an sr-only heading and the toolbar is the only content. Revisit only if real user testing indicates a need.
📚 Learning: 2025-10-03T07:55:42.639Z
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/manager/components/preview/Toolbar.tsx:102-105
Timestamp: 2025-10-03T07:55:42.639Z
Learning: In code/core/src/manager/components/preview/Toolbar.tsx, we intentionally do not add aria-label/aria-labelledby to StyledToolbar (AbstractToolbar) because the enclosing section is already labeled via an sr-only heading and the toolbar is the only content. Revisit only if real user testing indicates a need.

Applied to files:

  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
📚 Learning: 2025-11-05T09:37:25.920Z
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/components/components/tooltip/WithTooltip.tsx:54-96
Timestamp: 2025-11-05T09:37:25.920Z
Learning: Repo: storybookjs/storybook — In code/core/src/components/components/tooltip/WithTooltip.tsx, the legacy WithTooltip implementation is intentionally reintroduced for backward compatibility and is deprecated; maintainers (per Sidnioulz) do not want maintenance or improvements on it. Prefer WithTooltipNew/Popover; avoid suggesting changes to WithTooltip.* going forward.

Applied to files:

  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
📚 Learning: 2025-09-18T20:51:06.618Z
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/viewport/components/Tool.tsx:38-39
Timestamp: 2025-09-18T20:51:06.618Z
Learning: In viewport tool code, when using the `useGlobals` hook from storybook/manager-api, the third returned value `storyGlobals` is guaranteed by TypeScript to be defined (not undefined/null), making the `in` operator safe to use without additional null checks.

Applied to files:

  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
📚 Learning: 2025-09-18T20:51:06.618Z
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/viewport/components/Tool.tsx:38-39
Timestamp: 2025-09-18T20:51:06.618Z
Learning: The useGlobals hook from storybook/manager-api returns a tuple where the third element (storyGlobals) is typed as Globals, not Globals | undefined. This means TypeScript guarantees it's always defined, making the `in` operator safe to use without additional null checks.

Applied to files:

  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (3)
code/core/src/toolbar/components/ToolbarMenuSelect.tsx (3)

13-13: LGTM! Cleanup of unused import.

The removal of getSelectedTitle is correct since the dynamic title logic has been moved into the Select component via the showSelectedLabel prop.


43-43: LGTM! Correct use of immutable binding.

Changing title from let to const is correct since it's no longer mutated after the removal of the dynamic title resolution logic.


100-100: LGTM! Correctly fixes the dynamicTitle bug.

Passing showSelectedLabel={dynamicTitle} directly ties the display behavior to the toolbar's dynamicTitle configuration:

  • When dynamicTitle is false, the static title (line 102) is shown instead of the selected option's title
  • When dynamicTitle is true or undefined, the selected label is shown (dynamic behavior via Select's default)

This correctly addresses issue #33281.


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: 0

Caution

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

⚠️ Outside diff range comments (1)
code/core/src/components/components/Select/Select.tsx (1)

47-50: Update the comment to reflect conditional behavior.

The comment states the label "is replaced by the currently selected option's title" in single-select mode, but with the new showSelectedLabel prop, this only occurs when showSelectedLabel is true.

Apply this diff to update the documentation:

   /**
-   * Label for the Select component. In single-select mode, is replaced by the currently selected
-   * option's title.
+   * Label for the Select component. In single-select mode, is replaced by the currently selected
+   * option's title when showSelectedLabel is true.
    */
   children?: React.ReactNode;
🧹 Nitpick comments (1)
code/core/src/components/components/Select/Select.tsx (1)

507-512: Logic correctly implements the intended behavior.

The conditional rendering properly controls whether the selected option's title is displayed based on the showSelectedLabel prop, which solves the reported issue.

Optional refinement for edge cases:

The current logic (showSelectedLabel && selectedOptions[0]?.title) || children might not handle edge cases where title is a falsy value (empty string "" or numeric 0). If such titles are valid in your domain, consider this more explicit check:

-              {(showSelectedLabel && selectedOptions[0]?.title) || children}
+              {showSelectedLabel && selectedOptions[0] ? selectedOptions[0].title : children}

This ensures that any selected title (including falsy values) is displayed when showSelectedLabel is true, rather than falling back to children.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de619c1 and a3bc089.

📒 Files selected for processing (2)
  • code/core/src/components/components/Select/Select.tsx (3 hunks)
  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use ESLint and Prettier configurations that are enforced in the codebase

Files:

  • code/core/src/components/components/Select/Select.tsx
  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Enable TypeScript strict mode

Files:

  • code/core/src/components/components/Select/Select.tsx
  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
code/**/*.{ts,tsx,js,jsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{ts,tsx,js,jsx,mjs}: Use server-side logger from 'storybook/internal/node-logger' for Node.js code
Use client-side logger from 'storybook/internal/client-logger' for browser code
Do not use console.log, console.warn, or console.error directly unless in isolated files where importing loggers would significantly increase bundle size

Files:

  • code/core/src/components/components/Select/Select.tsx
  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
code/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Export functions that need to be tested from their modules

Files:

  • code/core/src/components/components/Select/Select.tsx
  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
code/**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{js,jsx,json,html,ts,tsx,mjs}: Run Prettier with --write flag to format code before committing
Run ESLint with yarn lint:js:cmd to check for linting issues and fix errors before committing

Files:

  • code/core/src/components/components/Select/Select.tsx
  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
🧠 Learnings (3)
📓 Common learnings
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/components/components/Tabs/Tabs.stories.tsx:222-227
Timestamp: 2025-11-05T09:36:55.944Z
Learning: Repo: storybookjs/storybook PR: 32458 — In code/core/src/components/components/Button/Button.tsx (React/TypeScript), ButtonProps includes ariaLabel?: string | false and the component maps it to the DOM aria-label. Convention: ariaLabel is mandatory on all Button usages — provide a descriptive string for icon-only buttons; set ariaLabel=false when the button’s children already serve as the accessible name. Do not suggest using a raw aria-label prop on Button call sites.
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/components/components/Select/Select.tsx:200-204
Timestamp: 2025-11-05T09:38:47.712Z
Learning: Repo: storybookjs/storybook — Guidance: Until Storybook 11 is released, do not suggest using React.useId anywhere (e.g., in code/core/src/components/components/Select/Select.tsx) to maintain compatibility with React 17 runtimes. Prefer advising: accept a caller-provided props.id and, if needed, generate a client-only fallback id to minimize SSR hydration issues — but avoid useId. Resume prompting for useId after Storybook 11.
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/manager/components/preview/Toolbar.tsx:102-105
Timestamp: 2025-10-03T07:55:42.639Z
Learning: In code/core/src/manager/components/preview/Toolbar.tsx, we intentionally do not add aria-label/aria-labelledby to StyledToolbar (AbstractToolbar) because the enclosing section is already labeled via an sr-only heading and the toolbar is the only content. Revisit only if real user testing indicates a need.
📚 Learning: 2025-11-05T09:36:55.944Z
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/components/components/Tabs/Tabs.stories.tsx:222-227
Timestamp: 2025-11-05T09:36:55.944Z
Learning: Repo: storybookjs/storybook PR: 32458 — In code/core/src/components/components/Button/Button.tsx (React/TypeScript), ButtonProps includes ariaLabel?: string | false and the component maps it to the DOM aria-label. Convention: ariaLabel is mandatory on all Button usages — provide a descriptive string for icon-only buttons; set ariaLabel=false when the button’s children already serve as the accessible name. Do not suggest using a raw aria-label prop on Button call sites.

Applied to files:

  • code/core/src/components/components/Select/Select.tsx
  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
📚 Learning: 2025-10-03T07:55:42.639Z
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/manager/components/preview/Toolbar.tsx:102-105
Timestamp: 2025-10-03T07:55:42.639Z
Learning: In code/core/src/manager/components/preview/Toolbar.tsx, we intentionally do not add aria-label/aria-labelledby to StyledToolbar (AbstractToolbar) because the enclosing section is already labeled via an sr-only heading and the toolbar is the only content. Revisit only if real user testing indicates a need.

Applied to files:

  • code/core/src/toolbar/components/ToolbarMenuSelect.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: normal
  • GitHub Check: nx
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (3)
code/core/src/components/components/Select/Select.tsx (2)

79-83: LGTM! Clear documentation for the new prop.

The showSelectedLabel prop is well-documented and appropriately optional with a sensible default.


208-208: LGTM! Default parameter correctly maintains backward compatibility.

code/core/src/toolbar/components/ToolbarMenuSelect.tsx (1)

104-104: Verify the showSelectedLabel={false} fix for dynamicTitle behavior in issue #33281.

Setting showSelectedLabel={false} should prevent the Select component from replacing the displayed title with the selected option's title when dynamicTitle is false. This appears to be the correct approach to fix the reported issue, with backward compatibility preserved (default showSelectedLabel={true} maintains existing behavior for other Select usages).

Manual verification recommended: Test with a toolbar configuration where dynamicTitle: false and confirm the toolbar title remains fixed when selecting different options from the dropdown.

onReset={() => updateGlobals({ [id]: '_reset' })}
onSelect={(selected) => updateGlobals({ [id]: selected })}
icon={icon && <Icons icon={icon} __suppressDeprecationWarning={true} />}
showSelectedLabel={false}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
showSelectedLabel={false}
showSelectedLabel={dynamicTitle}

otherwise it'll never update

Comment on lines 49 to 51
if (dynamicTitle) {
title = getSelectedTitle({ currentValue, items }) || title;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If we pass dynamicTitle through, then we can remove this logic and pass title through directly

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing that out — updated accordingly.

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.

[Bug]: Setting dynamicTitle to false in globals has no effect

2 participants