[Theme] TechButton ignores a caller-supplied disabled attribute (latent) #44

Closed
opened 2026-11-09 14:39:24 -05:00 by dohertj2 · 1 comment
Owner

From the scadaproj#15 shared-library review (code-reviews/Theme/findings.md, Theme-007), verified at 91fb2b4. Update the finding's Resolution row when fixed.

Severity Medium
Priority P2
Category Correctness & logic bugs
Status Open
Location ZB.MOM.WW.Theme/src/ZB.MOM.WW.Theme/Components/TechButton.razor:3

Description

The button is rendered as
<button @attributes="AdditionalAttributes" type="@Type" class="@ButtonClass" disabled="@Busy">.
In Blazor, an attribute written after an @attributes splat overrides the same-named splatted
attribute. disabled is not a declared parameter, so a caller's disabled="…" is captured into
AdditionalAttributes and then overwritten by disabled="@Busy". When Busy is false, Blazor drops
the attribute entirely. 0.5.0 added a merge for class (ButtonClass folds in the splatted class),
but disabled was not merged. The XML doc on AdditionalAttributes says "arbitrary additional HTML
attributes splatted onto the underlying <button>". The existing test
Class_composition_keeps_busy_type_and_click_behavior covers only the opposite direction
(Busy=true beating caller disabled=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 no disabled, so the button is
clickable 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 passes
disabled (20 .razor files use TechButton), so this is latent. It is still a natural use of the
documented splat, and any server-side authorization check would be the only backstop.

Recommendation

Compute the effective state as Busy || callerDisabled, where callerDisabled is read from
AdditionalAttributes["disabled"] with the same case-insensitive lookup used for class. Better still,
add an explicit [Parameter] public bool Disabled. Then render disabled="@(Busy || Disabled)". Add a
bUnit test for caller disabled=true with Busy=false.

Resolution

Unresolved.

From the scadaproj#15 shared-library review (`code-reviews/Theme/findings.md`, **Theme-007**), verified at 91fb2b4. Update the finding's Resolution row when fixed. | | | |--|--| | Severity | Medium | | Priority | P2 | | Category | Correctness & logic bugs | | Status | Open | | Location | `ZB.MOM.WW.Theme/src/ZB.MOM.WW.Theme/Components/TechButton.razor:3` | **Description** The button is rendered as `<button @attributes="AdditionalAttributes" type="@Type" class="@ButtonClass" disabled="@Busy">`. In Blazor, an attribute written after an `@attributes` splat overrides the same-named splatted attribute. `disabled` is not a declared parameter, so a caller's `disabled="…"` is captured into `AdditionalAttributes` and then overwritten by `disabled="@Busy"`. When `Busy` is `false`, Blazor drops the attribute entirely. 0.5.0 added a merge for `class` (`ButtonClass` folds in the splatted `class`), but `disabled` was not merged. The XML doc on `AdditionalAttributes` says "arbitrary additional HTML attributes splatted onto the underlying `<button>`". The existing test `Class_composition_keeps_busy_type_and_click_behavior` covers only the opposite direction (`Busy=true` beating caller `disabled=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 no `disabled`, so the button is clickable 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 passes `disabled` (20 `.razor` files use `TechButton`), so this is latent. It is still a natural use of the documented splat, and any server-side authorization check would be the only backstop. **Recommendation** Compute the effective state as `Busy || callerDisabled`, where `callerDisabled` is read from `AdditionalAttributes["disabled"]` with the same case-insensitive lookup used for `class`. Better still, add an explicit `[Parameter] public bool Disabled`. Then render `disabled="@(Busy || Disabled)"`. Add a bUnit test for caller `disabled=true` with `Busy=false`. **Resolution** _Unresolved._
dohertj2 added the type:review-findingpriority:p2 labels 2026-11-09 14:39:24 -05:00
Author
Owner

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.

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.
Sign in to join this conversation.