-
-
Notifications
You must be signed in to change notification settings - Fork 362
fix(AutoComplete): support bind value clear value function #6936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis PR adds support for a clear-value function in the AutoComplete component by introducing a JS-invokable TriggerClear method, updating the JS event handling and sample usage, and adding a unit test, while also refactoring TriggerChange to a void method. Sequence diagram for AutoComplete clear value interactionsequenceDiagram
participant User as actor User
participant UI as "AutoComplete UI"
participant JS as "AutoComplete.razor.js"
participant DotNet as "AutoComplete.razor.cs"
User->>UI: Click clear icon
UI->>JS: .clear-icon click event
JS->>DotNet: invokeMethodAsync('TriggerClear')
DotNet->>DotNet: TriggerClear()
DotNet->>DotNet: TriggerFilter("")
DotNet->>DotNet: _clientValue = null
DotNet->>DotNet: CurrentValueAsString = ""
Class diagram for updated AutoComplete componentclassDiagram
class AutoComplete {
+List<string> Rows
+Task TriggerFilter(string val)
+void TriggerChange(string v)
+async Task TriggerClear()
-List<string> GetFilterItemsByValue(string val)
-string _clientValue
-string CurrentValueAsString
}
AutoComplete : [JSInvokable] TriggerClear()
AutoComplete : [JSInvokable] TriggerChange(string v)
AutoComplete : [JSInvokable] TriggerFilter(string val)
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- TriggerClear doesn’t invoke the ValueChanged callback, so bound Value parameters won’t be notified of the cleared state—consider calling ValueChanged.InvokeAsync after clearing.
- For consistency with other JSInvokable methods, either have TriggerClear return a Task or rename it to TriggerClearAsync to match the async naming convention.
- Consider adding a test to verify that the clear icon only appears when IsClearable is true and that clicking it actually invokes TriggerClear.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- TriggerClear doesn’t invoke the ValueChanged callback, so bound Value parameters won’t be notified of the cleared state—consider calling ValueChanged.InvokeAsync after clearing.
- For consistency with other JSInvokable methods, either have TriggerClear return a Task or rename it to TriggerClearAsync to match the async naming convention.
- Consider adding a test to verify that the clear icon only appears when IsClearable is true and that clicking it actually invokes TriggerClear.
## Individual Comments
### Comment 1
<location> `test/UnitTest/Components/AutoCompleteTest.cs:199-208` </location>
<code_context>
Assert.Equal(2, menus.Count);
}
+ [Fact]
+ public async Task TriggerClear_Ok()
+ {
+ var val = "task1";
+ var items = new List<string>() { "task1", "Task2" };
+ var cut = Context.RenderComponent<AutoComplete>(builder =>
+ {
+ builder.Add(a => a.Items, items);
+ builder.Add(a => a.IgnoreCase, false);
+ builder.Add(a => a.Value, val);
+ builder.Add(a => a.IsClearable, true);
+ builder.Add(a => a.ValueChanged, EventCallback.Factory.Create<string?>(this, v =>
+ {
+ val = v;
+ }));
+ });
+
+ await cut.InvokeAsync(cut.Instance.TriggerClear);
+ Assert.Empty(val);
+ }
+
</code_context>
<issue_to_address>
**suggestion (testing):** Consider adding tests for edge cases when clearing the value.
Please add tests for clearing when the value is already empty, when Items is empty, and when IsClearable is false to ensure all edge cases are covered.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Fixes the AutoComplete component's clear value functionality to properly support bind value clearing when the clear button is clicked.
- Added a new
TriggerClearmethod that properly clears both client and server state - Updated JavaScript to call the new clear method instead of the generic filter method
- Simplified the
TriggerChangemethod by removing unnecessary async/await
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| AutoComplete.razor.cs | Added TriggerClear method and simplified TriggerChange method |
| AutoComplete.razor.js | Updated clear button handler to call TriggerClear instead of TriggerFilter |
| AutoCompleteTest.cs | Added unit test for the clear functionality |
| AutoCompletes.razor | Enabled clear button in demo for testing |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6936 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 740 740
Lines 31815 31819 +4
Branches 4469 4469
=========================================
+ Hits 31815 31819 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #6931
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Implement clear functionality in the AutoComplete component so that clicking the clear icon resets the bound value and filter, along with test and sample updates.
New Features:
Enhancements:
Documentation:
Tests: