[Theme] TechButton ignores a caller-supplied disabled attribute (latent) #44
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
From the scadaproj#15 shared-library review (
code-reviews/Theme/findings.md, Theme-007), verified at91fb2b4. Update the finding's Resolution row when fixed.ZB.MOM.WW.Theme/src/ZB.MOM.WW.Theme/Components/TechButton.razor:3Description
The button is rendered as
<button @attributes="AdditionalAttributes" type="@Type" class="@ButtonClass" disabled="@Busy">.In Blazor, an attribute written after an
@attributessplat overrides the same-named splattedattribute.
disabledis not a declared parameter, so a caller'sdisabled="…"is captured intoAdditionalAttributesand then overwritten bydisabled="@Busy". WhenBusyisfalse, Blazor dropsthe attribute entirely. 0.5.0 added a merge for
class(ButtonClassfolds in the splattedclass),but
disabledwas not merged. The XML doc onAdditionalAttributessays "arbitrary additional HTMLattributes splatted onto the underlying
<button>". The existing testClass_composition_keeps_busy_type_and_click_behaviorcovers only the opposite direction(
Busy=truebeating callerdisabled=false).Failure scenario
A page renders
<TechButton Variant="ButtonVariant.Danger" disabled="@(!CanDelete)" @onclick="Delete">Delete</TechButton>for a user who cannot delete, or for a form that is not yet valid. The output is
<button type="button" class="btn btn-danger">Delete</button>, with nodisabled, so the button isclickable and fires
Delete. A bUnit probe in the scratchpad confirmed this:Render<TechButton>(p => p.AddUnmatched("disabled", true))produced<button type="button" class="btn btn-primary">Delete</button>. No current family call site passesdisabled(20.razorfiles useTechButton), so this is latent. It is still a natural use of thedocumented splat, and any server-side authorization check would be the only backstop.
Recommendation
Compute the effective state as
Busy || callerDisabled, wherecallerDisabledis read fromAdditionalAttributes["disabled"]with the same case-insensitive lookup used forclass. Better still,add an explicit
[Parameter] public bool Disabled. Then renderdisabled="@(Busy || Disabled)". Add abUnit test for caller
disabled=truewithBusy=false.Resolution
Unresolved.
Fixed on main
a2e2f4b(Theme-007 → Resolved): TechButton is disabled when Busy or when the caller passes disabled, following Blazor's rules (false = enabled; true/"disabled"/"" = disabled). No new bool Disabled parameter — Blazor matches parameter names case-insensitively, so it would break callers passing disabled="disabled". Theme 0.5.0 → 0.5.1, unpublished. Evidence: Overview 195/195, Theme 65/65, GalaxyRepository 74/74; each regression test failed before its fix; code-reviews --check consistent.