Skip to content

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

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

atomiks merged 3 commits into
mui:masterfrom
vcode-sh:fix/select-value-placeholder-record-items

Conversation

@vcode-sh

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

Copy link
Copy Markdown
Contributor

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 #4136
@pkg-pr-new

pkg-pr-new Bot commented Feb 19, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/@base-ui/react@4137
    
    pnpm add https://pkg.pr.new/@base-ui/utils@4137
    

commit: 181f00f

@mui-bot

mui-bot commented Feb 19, 2026 •

Copy link
Copy Markdown

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

netlify Bot commented Feb 19, 2026 •

Copy link
Copy Markdown

✅ 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
Copy Markdown
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');
    });

@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
7 checks passed
@vcode-sh

Copy link
Copy Markdown
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