fix(theme): TechButton honours a caller-supplied disabled; bump 0.5.1 (scadaproj#44)
The trailing disabled="@Busy" overrode the splatted attribute, so a caller's disabled was dropped whenever Busy was false and the button stayed clickable. The effective state is now Busy || caller disabled (Blazor splat semantics). - tests: caller disabled (true/"disabled"/""), false, and re-render toggle - Directory.Build.props 0.5.0 -> 0.5.1 (NOT packed or published) - code-reviews: Theme-007 Resolved; README regenerated Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
@namespace ZB.MOM.WW.Theme
|
||||
@* Components/TechButton.razor *@
|
||||
<button @attributes="AdditionalAttributes" type="@Type" class="@ButtonClass" disabled="@Busy">
|
||||
<button @attributes="AdditionalAttributes" type="@Type" class="@ButtonClass" disabled="@(Busy || CallerDisabled)">
|
||||
@if (Busy) { <span class="spinner-border spinner-border-sm me-1" aria-hidden="true"></span> }
|
||||
@ChildContent
|
||||
</button>
|
||||
@@ -33,6 +33,8 @@
|
||||
/// <summary>
|
||||
/// Arbitrary additional HTML attributes splatted onto the underlying
|
||||
/// <c><button></c> (e.g. <c>id</c>, <c>@onclick</c>, <c>name</c>, <c>value</c>).
|
||||
/// A caller-supplied <c>class</c> is merged into the button's classes, and a caller-supplied
|
||||
/// <c>disabled</c> is OR-ed with <see cref="Busy"/> — the button is disabled when either asks.
|
||||
/// </summary>
|
||||
[Parameter(CaptureUnmatchedValues = true)] public IDictionary<string, object>? AdditionalAttributes { get; set; }
|
||||
|
||||
@@ -44,6 +46,13 @@
|
||||
AdditionalAttributes?.FirstOrDefault(pair => string.Equals(pair.Key, "class", StringComparison.OrdinalIgnoreCase)).Value?.ToString()
|
||||
}.Where(value => !string.IsNullOrWhiteSpace(value)));
|
||||
|
||||
// The trailing disabled="..." in the markup overrides a splatted one, so the caller's value has
|
||||
// to be folded in here or it is silently dropped (Theme-007). Mirrors Blazor's own rendering of
|
||||
// a splatted attribute: false/null omit it, anything else (true, "disabled", "") renders it.
|
||||
private bool CallerDisabled =>
|
||||
AdditionalAttributes?.FirstOrDefault(pair => string.Equals(pair.Key, "disabled", StringComparison.OrdinalIgnoreCase)).Value
|
||||
is { } value && value is not false;
|
||||
|
||||
private string VariantClass => Variant switch
|
||||
{
|
||||
ButtonVariant.Secondary => "btn-outline-secondary",
|
||||
|
||||
Reference in New Issue
Block a user