-
-
Notifications
You must be signed in to change notification settings - Fork 362
feat(AutoFill): reuse AutoComplete clear-icon function #6763
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 refactors the AutoFill component to reuse the AutoComplete clear-icon functionality by removing its duplicate clear logic, delegating clear behavior to the TriggerFilter method, updating the razor markup accordingly, and adapting unit tests to exercise the new clear path. Sequence diagram for clear action in AutoFill after refactorsequenceDiagram
participant User as actor User
participant AutoFill
participant JSInterop
participant OnClearAsync
User->>AutoFill: Click clear icon
AutoFill->>AutoFill: TriggerFilter("")
AutoFill->>JSInterop: setValue(Id, "")
AutoFill->>OnClearAsync: (if exists) await OnClearAsync()
AutoFill->>AutoFill: Reset CurrentValue, _filterItems, _displayText
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.
Pull Request Overview
This pull request refactors the AutoFill component to reuse the AutoComplete clear-icon functionality by consolidating the clear logic into the existing TriggerFilter method instead of maintaining a separate OnClearValue method.
Key changes:
- Consolidates clear functionality into the
TriggerFiltermethod when an empty string is passed - Removes the duplicate
OnClearValuemethod and its click handler - Updates tests to use the unified clear mechanism
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| AutoFill.razor.cs | Removes duplicate OnClearValue method and adds clear logic to TriggerFilter method |
| AutoFill.razor | Removes click handler from clear icon span element |
| AutoFillTest.cs | Updates tests to use TriggerFilter("") instead of clicking clear button |
| BootstrapBlazor.csproj | Increments version from 9.10.1 to 9.10.2 |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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:
- Ensure the clear-icon click is still wired up correctly after removing OnClearValue and the @OnClick, so that clicking it invokes TriggerFilter("") as intended.
- Consider reintroducing the virtualize element refresh in the empty-val branch of TriggerFilter to mirror the previous OnClearValue behavior and fully clear the dropdown.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Ensure the clear-icon click is still wired up correctly after removing OnClearValue and the @onclick, so that clicking it invokes TriggerFilter("") as intended.
- Consider reintroducing the virtualize element refresh in the empty-val branch of TriggerFilter to mirror the previous OnClearValue behavior and fully clear the dropdown.
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor/Components/AutoFill/AutoFill.razor:22` </location>
<code_context>
<span class="form-select-append ac-loading"><i class="@LoadingIcon"></i></span>
@if (GetClearable())
{
- <span class="@ClearClassString" @onclick="OnClearValue"><i class="@ClearIcon"></i></span>
+ <span class="@ClearClassString"><i class="@ClearIcon"></i></span>
}
<RenderTemplate @ref="_dropdown">
</code_context>
<issue_to_address>
**issue (bug_risk):** Removing the @onclick handler from the clear icon may break expected clear functionality.
Without the click handler, users may lose the ability to clear the input. If this change was not intentional, please restore the handler or provide another way to clear the value.
</issue_to_address>
### Comment 2
<location> `test/UnitTest/Components/AutoFillTest.cs:428-430` </location>
<code_context>
Assert.Equal("2", searchText);
Assert.Contains("<div>test2</div>", cut.Markup);
+ // 测试 Clear 清空逻辑
query = false;
- // 点击 Clear 按钮
- var button = cut.Find(".clear-icon");
- await cut.InvokeAsync(() => button.Click());
+ await cut.InvokeAsync(() => cut.Instance.TriggerFilter(""));
Assert.True(query);
</code_context>
<issue_to_address>
**suggestion (testing):** Consider adding a test for clearing when the input is already empty.
Adding this test will verify that calling TriggerFilter("") on an already empty input does not introduce side effects and that the clear logic behaves consistently.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Link issues
fixes #6762
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Reuse AutoComplete's clear-icon functionality in AutoFill by removing the custom clearing handler and delegating clear events to TriggerFilter, ensuring component state resets correctly when cleared.
Bug Fixes:
Enhancements:
Tests: