Skip to content

[select] Fix SelectValue placeholder not rendered with Record items#4137

Merged
atomiks merged 3 commits intomui:masterfrom
vcode-sh:fix/select-value-placeholder-record-items
Feb 19, 2026
Merged

[select] Fix SelectValue placeholder not rendered with Record items#4137
atomiks merged 3 commits intomui:masterfrom
vcode-sh:fix/select-value-placeholder-record-items

Conversation

@vcode-sh
Copy link
Contributor

@vcode-sh vcode-sh commented Feb 19, 2026

Summary

<Select.Value placeholder="..." /> renders an empty <span> when items is a Record<string, ReactNode> without a "null" key. This is caused by inverted logic in hasNullItemLabel().

The same function is shared by Combobox, so <Combobox.Value placeholder="..." /> with Record items is also affected.

Before (buggy):

// packages/react/src/utils/resolveValueLabel.tsx
if (!Array.isArray(items)) {
  return items != null && !('null' in items);
}

For { sans: "Sans-serif", serif: "Serif" }:

  • !('null' in items)true → returns true
  • SelectValue skips the placeholder because it thinks the null value already has a label

After (fixed):

if (!Array.isArray(items)) {
  return items != null && 'null' in items;
}

Changes

  • resolveValueLabel.tsx: Remove the ! operator in the Record branch of hasNullItemLabel()
  • resolveValueLabel.test.ts: Add tests for Record items (with and without "null" key), flat array items, and undefined

Fixes #4136

The `hasNullItemLabel` function had inverted logic for the Record
branch: `!('null' in items)` returned `true` when no `"null"` key
existed, incorrectly suppressing the `placeholder` prop on
`SelectValue`.

Removes the `!` operator so Record items without a `"null"` key
correctly return `false`, allowing the placeholder to render.

Adds tests for Record items, flat array items, and undefined.

Fixes mui#4136
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 19, 2026

commit: 181f00f

@mui-bot
Copy link

mui-bot commented Feb 19, 2026

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react ▼-3B(0.00%) ▼-1B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify
Copy link

netlify bot commented Feb 19, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 181f00f
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6996d1b3015a180008482591
😎 Deploy Preview https://deploy-preview-4137--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment on lines +45 to +48
it('returns true when flat items contain a null-valued item with a label', () => {
const items = [
{ value: 'a', label: 'A' },
{ value: null, label: 'None' },
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix @vcode-sh, can you add these to SelectValue.test.tsx too:

    it('displays placeholder when object items do not have a null key', async () => {
      const items = {
        option1: 'Option 1',
        option2: 'Option 2',
      };

      await render(
        <Select.Root items={items}>
          <Select.Value data-testid="value" placeholder="Select an option" />
        </Select.Root>,
      );

      expect(screen.getByTestId('value')).to.have.text('Select an option');
    });

    it('null key label in object items takes precedence over placeholder', async () => {
      const items = {
        null: 'None',
        option1: 'Option 1',
      };

      await render(
        <Select.Root items={items}>
          <Select.Value data-testid="value" placeholder="Select an option" />
        </Select.Root>,
      );

      expect(screen.getByTestId('value')).to.have.text('None');
    });

Co-authored-by: atomiks <atomiks@users.noreply.github.com>
@atomiks atomiks added component: select Changes related to the select component. type: bug It doesn't behave as expected. labels Feb 19, 2026
@atomiks atomiks merged commit b0fc1cb into mui:master Feb 19, 2026
23 checks passed
@vcode-sh
Copy link
Contributor Author

Thanks @atomiks

@vcode-sh vcode-sh deleted the fix/select-value-placeholder-record-items branch February 21, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: select Changes related to the select component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[select] SelectValue placeholder not rendered when items is a Record without a "null" key

3 participants