Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Sep 19, 2025

Link issues

fixes #6762

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

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:

  • Remove the custom OnClearValue method in AutoFill and leverage the shared AutoComplete clear-icon logic

Tests:

  • Update unit tests to trigger clear logic via TriggerFilter("") instead of simulating clear-icon clicks

Copilot AI review requested due to automatic review settings September 19, 2025 02:32
@bb-auto bb-auto bot added the enhancement New feature or request label Sep 19, 2025
@bb-auto bb-auto bot added this to the 9.10.0 milestone Sep 19, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 19, 2025

Reviewer's Guide

This 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 refactor

sequenceDiagram
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
Loading

File-Level Changes

Change Details Files
Refactor AutoFill clear-icon implementation
  • Relocate ClassString definition
  • Remove redundant OnClearValue method
  • Extend TriggerFilter to reset state on empty input
  • Adjust razor markup to drop direct OnClearValue onclick
src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs
src/BootstrapBlazor/Components/AutoFill/AutoFill.razor
Update unit tests to match new clear logic
  • Replace clear-icon button.Click with TriggerFilter("")
  • Add assertions to verify clear behavior
test/UnitTest/Components/AutoFillTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#6762 Refactor AutoFill component to reuse the clear-icon function from AutoComplete, ensuring consistent clear behavior.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

Copilot AI left a 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 TriggerFilter method when an empty string is passed
  • Removes the duplicate OnClearValue method 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.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(AutoFill): reuse AutoComplete clear-icon function

2 participants