Registry Mirror
Skip to content

Conversation

@phmatray

@phmatray phmatray commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Implements #476.

Closes #476.

.DisabledWhen(...) stored its condition on IFieldConfiguration.DisabledCondition, but nothing ever evaluated it. Every field component in both adapters binds Disabled="@IsDisabled" from FieldComponentBase, which read only the static IsDisabled flag.

Why this deviates from the plan's fix site. The plan put the check in each adapter's FormCraftComponent.razor.cs, next to VisibilityCondition. That spot has nothing to plug into: visibility gates whether a field renders (an @if), but FormCraftComponent never passes a per-field Disabled parameter. The seam both adapters actually go through is FieldComponentBase.IsDisabled, which the Spec's "minimal core seam they both call through" clause allows. The fix is one line there:

protected bool IsDisabled => Context.Field.DisabledCondition?.Invoke(Context.Model) ?? Context.Field.IsDisabled;
  • It is read during render, so the condition is re-evaluated on every render pass, including after the watched field changes.
  • When the condition is set, it takes precedence over .Disabled(bool), as IFieldConfiguration's doc comment already said.
  • The Lookup and LOV click guards read the same property, so they follow it too.

Tests. A DisabledWhenRenderingTests class in each adapter suite, with 4 facts each:

  • disabled at first render
  • follows the watched field false → true → false
  • the static .Disabled() flag still works without a condition
  • the condition wins over the static flag

Without the fix, 3 of the 4 fail in each adapter. Full suite: 2075/2075 green on the tree merged with dev; dotnet format --verify-no-changes is clean.

Focus (CLAUDE.md 2.4.3): not triggered. The control that becomes disabled is the dependent field, not the one being activated. A caller who writes a condition on a field's own value could make it disable itself, but that is the same configuration VisibleWhen already allows.

Plan

  • Task 1: Wire DisabledCondition into MudBlazor's render pass and prove it
  • Task 2: Wire DisabledCondition into FluentUI's render pass and prove it

Follow-ups

  • MudBlazor file upload components (MudBlazorFileUploadFieldComponent.razor, MudBlazorMultipleFileUploadComponent.razor) never bind IsDisabled, so neither .Disabled() nor .DisabledWhen(...) disables them (MudFileUpload, the drop zone, Browse and Clear stay active). Their Fluent counterparts do bind it. This predates this PR (found in review).
  • The core stub renderers (FormCraft/Forms/Rendering/{String,Int,Decimal,Double,Bool,DateTime,FileUpload}FieldRenderer.cs) still read Context.Field.IsDisabled directly, so they ignore DisabledWhen. They are only used when no adapter is registered.
  • FieldContext (custom templates) has no disabled state, so template authors have to evaluate DisabledCondition themselves. Either document that or expose an effective-disabled value.

🤖 Generated with Claude Code

phmatray and others added 4 commits September 24, 2026 10:35
Fixed once in FieldComponentBase.IsDisabled, the seam every component of both adapters binds Disabled to; FormCraftComponent never feeds a per-field Disabled parameter, so the planned per-adapter site had nothing to plug into.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@phmatray
phmatray marked this pull request as ready for review September 24, 2026 08:41
@phmatray
phmatray merged commit e51c9ef into dev Sep 24, 2026
4 checks passed
@phmatray
phmatray deleted the fix/476-disabledwhen-is-never-evaluated branch September 24, 2026 08:48
phmatray added a commit that referenced this pull request Sep 24, 2026
…#487)

* fix(mudblazor): bind IsDisabled to the single-file upload component

MudBlazorFileUploadFieldComponent never bound Disabled, so .Disabled()/
.DisabledWhen(...) had no effect: MudFileUpload, the Browse button, and the
Clear button stayed active. Bind Disabled="@IsDisabled" on all three, and
guard OpenFilePickerAsync() directly since the MudPaper drop zone's @OnClick
calls it without going through any Disabled-bound control.

Follow-up from #479.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(mudblazor): bind IsDisabled to the multiple-file upload component

MudBlazorMultipleFileUploadComponent had the same gap as the single-file
component: Disabled was never bound, so .Disabled()/.DisabledWhen(...) left
MudFileUpload, Browse and Clear All active. Bind Disabled="@IsDisabled" on
all three, guard OpenFilePickerAsync() for the same drop-zone reason as the
single-file component, and guard RemoveFile(...) since a file chip's close
callback is FormCraft's own CustomContent and no Disabled binding reaches it.

Follow-up from #479.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* test(mudblazor): cover the drop-zone click path for disabled file uploads

Both OpenFilePickerAsync() guards were untested: the Browse button's own
Disabled binding already blocks a click there, so the only path that
exercises the guard is the MudPaper drop zone's own @OnClick, which calls
OpenFilePickerAsync() directly. Add one fact per component with a positive
control (enabled: the click does open the picker) before the negative
(disabled: it does not), so a wrong selector cannot pass silently.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(mudblazor): guard SetDragClass against a disabled file-upload field

Review of #482 found the same bypass in SetDragClass() that OpenFilePickerAsync
already guarded: @ondragenter is FormCraft's own MudPaper handler, not gated
by MudFileUpload's Disabled, so a disabled field still showed drag-hover
feedback (the highlight class, the transparent capture input unhidden) even
though the actual drop is already blocked at the MudBlazor layer. Also adds
the one direct assertion the new tests were missing: the single-file Clear
button's Disabled binding with a file already present.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
phmatray added a commit that referenced this pull request Sep 24, 2026
…#483) (#489)

* fix(core): resolve DisabledCondition in the core stub field renderers

The seven core stub renderers under FormCraft/Forms/Rendering/ read
Context.Field.IsDisabled directly, so .DisabledWhen(...) had no effect on the
no-adapter-registered fallback path even though FieldComponentBase.IsDisabled
already resolves it correctly for both UI adapters (#479).

Apply the same expression here:
Context.Field.DisabledCondition?.Invoke(Context.Model) ?? Context.Field.IsDisabled

Also stub IFieldConfiguration.DisabledCondition to null in the existing
Fake-based test helpers across these seven test files: FakeItEasy returns a
dummy Func<TModel,bool> (not null) for an unconfigured delegate property, and
invoking it returns false, which was silently overriding an explicitly
stubbed IsDisabled=true once the renderers started reading DisabledCondition
first.

Closes #483

* test(core): replace internal-state assertions with rendered-DOM checks

FileUploadFieldRendererTests had two pre-existing assertions that checked
internal state rather than rendered output (out of scope for #478/#486,
which targeted ShouldNotBeNull()):

- Render_WithMultipleFilesConfiguration_ConfiguresForMultipleUpload asserted
  uploadConfig.Multiple.ShouldBeTrue() — an Arrange-time fact about the config
  object, not the rendered DOM. Replaced with a DOM assertion that "accept"
  stays absent, consistent with the sibling tests' documented fact that this
  stub never reads FileUploadConfiguration.
- Render_ClearsValidationErrors_OnSuccessfulUpload asserted
  additionalAttributes.ShouldNotContainKey("FileUploadErrors") against a dict
  the renderer never touches. Replaced with a DOM assertion that "multiple"
  stays absent, matching the same fixed-markup fact already established in
  the file's other CurrentValue-driven tests.

Closes #488

* fix: address code-review findings

- FileUploadFieldRendererTests: give the two rendered-DOM replacement
  assertions (#488) something real to pin instead of proving "nothing is
  emitted from nothing" — set AcceptedFileTypes on the FileUploadConfiguration
  the "accept" assertion checks against, and stub ActualFieldType so the
  "multiple" assertion actually reflects a single-file scenario.
- CoreRendererDisabledWhenTests: assert the file-upload facts render an
  <input type="file"> in addition to the disabled state, so a future
  regression that accidentally resolved a different renderer for the field
  would be caught rather than silently asserting on the wrong element.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: DisabledWhen never evaluated at render time in either adapter

1 participant