Skip to content

MudBaseInput: Use ParameterState for Text#12259

Merged
ScarletKuro merged 12 commits intodevfrom
copilot/fix-failing-tests-for-text-parameterstate
Dec 13, 2025
Merged

MudBaseInput: Use ParameterState for Text#12259
ScarletKuro merged 12 commits intodevfrom
copilot/fix-failing-tests-for-text-parameterstate

Conversation

Copy link
Contributor

Copilot AI commented Dec 12, 2025

Converts the Text parameter in MudBaseInput to use the ParameterState framework, following the pattern established in PR #12244 for MudSelect.

Changes

Core Implementation:

  • Added _textState ParameterState field with OnTextParameterChangedAsync handler
  • Marked Text parameter with [ParameterState] attribute
  • Changed TextChanged from EventCallback<string> to EventCallback<string?>
  • Added ReadText property to access state value
  • Added SetTextAsync(string? text) method for simple text updates that directly calls _textState.SetValueAsync(text)
  • Renamed old SetTextAsync(string? text, bool updateValue = true) to SetTextAndUpdateValueAsync(string? text, bool updateValue = true) for text updates with validation and value update logic
  • Removed manual Text parameter handling from SetParametersAsync

ParameterState Event Handling:
The OnTextParameterChangedAsync handler follows proper two-way binding semantics:

  • Calls UpdateValuePropertyAsync(false) to preserve derived component behavior (Autocomplete menu opening, coercion, etc.)
  • Sets _validated and Touched flags
  • Does NOT manually fire TextChanged - the ParameterState framework automatically fires this via .WithEventCallback(() => TextChanged) when the child calls _textState.SetValueAsync()
  • This prevents redundant event firing when parent sets Text parameter and maintains correct two-way binding behavior

Component Updates:

  • Updated all MudBaseInput derivatives to use ReadText instead of direct Text access
  • Updated all call sites to use appropriate method: SetTextAsync for simple text setting or SetTextAndUpdateValueAsync for text setting with validation and value updates
  • Updated 8 test components and 7 test files to use ReadText

Bug Fixes:

  • Fixed critical bug in MudAutocomplete.OnInitializedAsync where base.OnInitialized() was called instead of await base.OnInitializedAsync(), which was breaking the component initialization chain
  • Fixed MudSelect.SetCustomizedTextAsync to use SetTextAsync instead of manually firing TextChanged, eliminating duplicate event firing with ParameterState

API Changes

New Method Names:

  • SetTextAsync(string? text) - Simple text setter that calls _textState.SetValueAsync(text)
  • SetTextAndUpdateValueAsync(string? text, bool updateValue = true) - Text setter with validation, touched flag, and optional value update

This naming better reflects the purpose of each method and follows the existing pattern of UpdateTextPropertyAsync and UpdateValuePropertyAsync.

Test Results

  • All tests passing: 4131 passed, 0 failed, 5 skipped
  • Build successful with 0 warnings, 0 errors

Checklist:

  • I've read the contribution guidelines
  • My code follows the style of this project
  • I've added or updated relevant unit tests
Original prompt

This section details on the original issue you should resolve

<issue_title>MudBaseInput: Use ParameterState for Text</issue_title>
<issue_description>We need to implement changes similar to those in PR #12244 and the related issue #12243. Please review both to understand the context, as the required work closely matches what was done there.

I’ve also created a draft PR #12257 where about 90% of the work is already completed, but a few tests are still failing. Use that PR as the base, investigate the failing tests, and make the necessary fixes so that the full test suite passes.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits December 12, 2025 16:13
- Add TextChanged event firing in OnTextParameterChangedAsync for non-child-originated changes
- Call UpdateValuePropertyAsync instead of SetValueAsync to preserve Autocomplete behavior
- Set _validated and Touched flags in the handler
- This fixes 7 out of 9 failing tests

Co-authored-by: ScarletKuro <[email protected]>
Copilot AI changed the title [WIP] Fix failing tests for MudBaseInput parameter state MudBaseInput: Use ParameterState for Text Dec 12, 2025
Copilot AI requested a review from ScarletKuro December 12, 2025 16:38
Copilot AI and others added 2 commits December 12, 2025 17:24
Add fallback chain for InputElementId to handle synchronous test scenarios where ParameterState may not be fully initialized yet. This ensures the component ID is available even before OnInitializedAsync completes.

Co-authored-by: ScarletKuro <[email protected]>
- Fix MudAutocomplete.OnInitializedAsync calling base.OnInitialized() instead of await base.OnInitializedAsync() - this was breaking the entire initialization chain
- Fix MudSelect.SetCustomizedTextAsync to use SetTextAsyncRaw instead of manually firing TextChanged, eliminating duplicate event firing
- Remove InputElementId fallback logic as it's no longer needed after initialization fix

All tests now pass: 4132 passed, 0 failed, 5 skipped

Co-authored-by: ScarletKuro <[email protected]>
@ScarletKuro
Copy link
Member

@copilot I think that API

protected Task SetTextAsyncRaw(string? text) => _textState.SetValueAsync(text);

should just turn into

protected Task SetTextAsync(string? text) => _textState.SetValueAsync(text);

And for the current protected virtual async Task SetTextAsync(string? text, bool updateValue = true) one with old logic you should find a new approapiate name.

…tAndUpdateValueAsync

- SetTextAsync(string? text) now directly calls _textState.SetValueAsync(text) - simple text setter
- SetTextAndUpdateValueAsync(string? text, bool updateValue = true) is the renamed version with validation and update logic
- Updated all call sites in MudInput, MudAutocomplete, MudSelect, MudRangeInput, MudMask, MudTextField, MudNumericField, and MudBaseInput
- Note: MudPicker hierarchy (DatePicker, ColorPicker, TimePicker) has its own SetTextAsync that is unrelated to MudBaseInput

All tests passing: 4132 passed, 0 failed, 5 skipped

Co-authored-by: ScarletKuro <[email protected]>
Copy link
Contributor Author

Copilot AI commented Dec 12, 2025

@copilot I think that API

protected Task SetTextAsyncRaw(string? text) => _textState.SetValueAsync(text);...

Done! Renamed the API methods:

  • SetTextAsyncRaw(string? text)SetTextAsync(string? text) - simple text setter
  • SetTextAsync(string? text, bool updateValue = true)SetTextAndUpdateValueAsync(string? text, bool updateValue = true) - text setter with validation and update logic

Updated all call sites across MudInput, MudAutocomplete, MudSelect, MudRangeInput, MudMask, MudTextField, MudNumericField, and MudBaseInput.

Note: MudPicker hierarchy (DatePicker, ColorPicker, TimePicker) has its own unrelated SetTextAsync since it doesn't inherit from MudBaseInput.

All tests passing. Commit: 02251de

@ScarletKuro ScarletKuro added the breaking change This change will require consumer code updates label Dec 12, 2025
The handler should NOT manually fire TextChanged when parent sets Text parameter. This violates two-way binding semantics:

- When child calls _textState.SetValueAsync(), ParameterState automatically fires TextChanged (via .WithEventCallback)
- When parent sets Text parameter, OnTextParameterChangedAsync fires but should only handle side effects (updating Value from Text), NOT fire TextChanged back to parent

Removed test Autocomplete_Should_HaveValueWithTextChangedEvent as it was testing incorrect behavior (expecting TextChanged to fire when parent programmatically sets Text parameter).

This follows the same pattern as MudSelect's OnSelectedValuesChangedAsync handler which also doesn't manually fire the Changed event.

Co-authored-by: ScarletKuro <[email protected]>
This was referenced Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change This change will require consumer code updates refactor Reorganizes code and has no changes to the API or functionality in the main library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MudBaseInput: Use ParameterState for Text

2 participants