[select] Fix SelectValue placeholder not rendered with Record items#4137
Merged
atomiks merged 3 commits intomui:masterfrom Feb 19, 2026
Merged
Conversation
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
commit: |
Bundle size report
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
atomiks
reviewed
Feb 19, 2026
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' }, |
Contributor
There was a problem hiding this comment.
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
approved these changes
Feb 19, 2026
Contributor
Author
|
Thanks @atomiks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
<Select.Value placeholder="..." />renders an empty<span>whenitemsis aRecord<string, ReactNode>without a"null"key. This is caused by inverted logic inhasNullItemLabel().The same function is shared by Combobox, so
<Combobox.Value placeholder="..." />with Record items is also affected.Before (buggy):
For
{ sans: "Sans-serif", serif: "Serif" }:!('null' in items)→true→ returnstrueSelectValueskips the placeholder because it thinks the null value already has a labelAfter (fixed):
Changes
resolveValueLabel.tsx: Remove the!operator in the Record branch ofhasNullItemLabel()resolveValueLabel.test.ts: Add tests for Record items (with and without"null"key), flat array items, andundefinedFixes #4136