Repository navigation
feat(mudblazor): make ShrinkLabel configurable per field and per form (#177) - #178
Merged
Merged
Conversation
MudBlazor ORs ShrinkLabel with has-value / has-placeholder / has-start-adornment before deciding the mud-shrink class, so ShrinkLabel=false is only observable on an empty field with none of those. The parameter-level tests could not see this because they assert the value passed in, not the rendering. - Add ShrinkLabelRenderingTests asserting the rendered mud-shrink class, pinning both where the setting works and where MudBlazor overrides it. - Document the caveat on WithShrinkLabel, DefaultShrinkLabel and in the README. - Correct the README claim of a LOV visual change: measured against the base commit, LOV labels were already pinned via its own placeholder, so this PR changes nothing visually. Keep the ShrinkLabel pass-through for consistency, with a comment saying it cannot affect that component's rendering.
phmatray
marked this pull request as ready for review
August 11, 2026 10:15
This was referenced Aug 11, 2026
This was referenced Sep 28, 2026
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.
Implements #177.
Closes #177.
Follow-up to #146:
ShrinkLabel="true"is hardcoded at 12 sites, soVariant.Textrenders a permanently-pinned label over a borderless input. This makes it configurable through the same channelVariantalready uses — field-level.WithShrinkLabel(bool)over form-levelDefaultShrinkLabel, resolving totruewhen unset so no existing form changes appearance.Plan
.WithShrinkLabel(...), honored by the text fieldDefaultShrinkLabel+ precedence.razorcomponentsRenderTreeBuilderpath)ShrinkLabel(flagged — behavior change)Known limitation —
ShrinkLabel="false"is not always observableWorth reading before reviewing, because it bounds what this PR actually delivers.
MudBlazor does not use
ShrinkLabelas the last word.MudInputdecides themud-shrinkclass by OR-ing it with several other conditions:So
.WithShrinkLabel(false)is only visible on an empty field with no placeholder and no start adornment. A field configured with.WithPlaceholder(...)keeps its label pinned whatever you pass.This is MudBlazor's rule, not something this PR can fix without silently discarding the user's placeholder — so it is documented instead: on
WithShrinkLabel, onDefaultShrinkLabel, and as an[!IMPORTANT]callout in the README next to the usage example.ShrinkLabelRenderingTestsasserts the renderedmud-shrinkclass in both directions so the boundary is a tested fact rather than folklore.Correction: the LOV field has no visual change
An earlier revision of this description and of the README claimed LOV labels "started floating while every sibling pinned it" and were "now aligned". That was wrong, and the code review caught it.
Measured by reverting the one-line change and re-running the rendering test against the base commit: LOV labels were already pinned before this PR, because the LOV input always supplies its own
"Click to select..."placeholder and MudBlazor's placeholder rule shrinks the label on its own. The rendering is byte-identical with and without the change.The
ShrinkLabel="@EffectiveShrinkLabel"pass-through is kept — it makes the component consistent with its 11 siblings and stops a future reader from "fixing" the asymmetry again — but it is now marked in the razor as unable to affect that component's rendering, andShrinkLabelRenderingTests.LovField_Label_Is_Always_Pinned_Regardless_Of_ShrinkLabellocks that in.Net result: this PR changes no existing form's appearance at all. The default resolves to
trueeverywhere, and the two pre-existing parity assertions (RenderPipelineParityTests.cs:237and:257, bothShrinkLabel.ShouldBeTrue()) stay green unmodified — they are the back-compat guard.Follow-ups
Found while working, deliberately not fixed here to keep this PR scoped:
LovBuilder.WithDisplaycannot be called with a bare lambda. It declares bothWithDisplay(Expression<Func<TItem, string>>)andWithDisplay(Func<TItem, string>), solov.WithDisplay(c => c.Name)fails withCS0121: the call is ambiguous— the natural call site, and the exact form used in the library's own XML-doc examples. Callers must write(Expression<Func<CityDto, string>>)(c => c.Name), which the tests here do with a comment explaining why. Fixing it means renaming one overload or dropping theFunc<>one (a breaking change), so it wants its own issue.Variant.Textfield should suppress a placeholder. Given the OR rule above, a placeholder and a floating label are mutually exclusive in MudBlazor. FormCraft could surface that trade-off explicitly rather than lettingShrinkLabelquietly lose. Deliberately out of scope here — it changes rendering for existing forms.