MudSelect: Give ToStringFunc Higher Precedence#12837
MudSelect: Give ToStringFunc Higher Precedence#12837danielchalmers merged 6 commits intoMudBlazor:devfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Updates MudSelect selection rendering so a provided ToStringFunc takes precedence over a selected item's ChildContent when determining what text is shown in the collapsed select box (and aligns FitContent sizing and docs/tests with that behavior).
Changes:
- Adjust selection rendering logic to prefer
ToStringFuncoutput (when non-empty) over selected itemChildContent. - Update
FitContentfiller rendering to reflect the new precedence. - Add unit tests, a test component, and documentation/example updates for the new behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/MudBlazor/Components/Select/MudSelect.razor.cs | Updates render decision (CanRenderValue) so non-empty ToStringFunc disables ChildContent presenter for the selected value. |
| src/MudBlazor/Components/Select/MudSelect.razor | Updates FitContent filler rendering to prefer ToStringFunc text when available. |
| src/MudBlazor.UnitTests/Components/SelectTests.cs | Adds coverage for selection display precedence and FitContent behavior with ToStringFunc. |
| src/MudBlazor.UnitTests.Viewer/TestComponents/Select/SelectPrecedenceTest.razor | Adds a viewer test component used by the new unit tests. |
| src/MudBlazor.Docs/Pages/Components/Select/SelectPage.razor | Documents the new precedence behavior. |
| src/MudBlazor.Docs/Pages/Components/Select/Examples/SelectPresentationExample.razor | Adds an example demonstrating ToStringFunc precedence with item render fragments. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/MudBlazor.UnitTests.Viewer/TestComponents/Select/SelectPrecedenceTest.razor
Outdated
Show resolved
Hide resolved
src/MudBlazor.UnitTests.Viewer/TestComponents/Select/SelectPrecedenceTest.razor
Outdated
Show resolved
Hide resolved
versile2
left a comment
There was a problem hiding this comment.
Ok all of the code is good. I like it, but it is a breaking change. I do not believe we can implement a breaking change in the beginning of a release cycle unless it is directly related to a major bug so I have a suggestion, perhaps @ScarletKuro can provide direction as to the best path forward.
Currently all consumers are forced to use ChildContent when it exists for their MudSelectItem, then ToStringFunc, and finally defaults to a default implemention of .ToString() of the object/class.
Keep that behavior but add a property on the MudSelectItem that says ShowContent with a default to ChildContent that can be toggled to ChildContent and ToStringFunc, add a note on the V10 project board to make the breaking change.
V
When you use This change allows both to work together.
|
Solid Reasoning and I agree. Can you clarify the documentation a bit for future people looking. |
|
The PR includes the following addition to the doc
|


This PR implements the request in issue #12729 by changing the precedence of how the selected value is displayed in
MudSelect.Previously, if a
MudSelectItemhadChildContent(aRenderFragment), it would always be used for the selection display in the select box, even if the parentMudSelecthad aToStringFuncdefined.With this change:
ToStringFuncis provided and returns a non-null, non-empty string for the selected value, that string will be displayed in the select box (as text).ToStringFuncis not provided, or returns a null/empty string, the component falls back to displaying theChildContentof the selected item (if any).ChildContentas before.FitContentproperty correctly accounts for this precedence when calculating the required width of the component.Closes #12729
Checklist: