Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Sep 18, 2025

Link issues

fixes #6732

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

Enable an optional clear button in the AutoComplete component via the new IsClearable parameter, including clear icon customization, updated markup and styling, JavaScript event handling, sample usage, and a unit test.

New Features:

  • Add IsClearable parameter to PopoverCompleteBase and AutoComplete to enable a clearable input
  • Introduce ClearIcon parameter for customizing the clear button icon
  • Implement JavaScript handler to clear the input and retrigger filtering on clear button click

Enhancements:

  • Apply conditional CSS class and markup to render and style the clear button
  • Demonstrate the clearable feature in the AutoComplete sample page

Tests:

  • Add unit test to verify the clear icon is rendered when IsClearable is enabled

Copilot AI review requested due to automatic review settings September 18, 2025 06:56
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 18, 2025

Reviewer's Guide

Introduces an IsClearable option to the AutoComplete component, implemented via new parameters, code-behind logic, markup updates, JS event handlers, unit tests, and sample adjustments to enable and demonstrate the clearable feature.

Sequence diagram for clear icon click interaction in AutoComplete

sequenceDiagram
    participant User as actor User
    participant UI as "AutoComplete UI"
    participant JS as "AutoComplete.razor.js"
    participant Blazor as "Blazor Component"
    User->>UI: Clicks clear icon
    UI->>JS: .clear-icon click event
    JS->>JS: input.value = ''
    JS->>Blazor: invokeMethodAsync('TriggerFilter', '')
Loading

File-Level Changes

Change Details Files
Add IsClearable and ClearIcon parameters with supporting logic
  • Define IsClearable and ClearIcon parameters in PopoverCompleteBase
  • Implement GetClearable() and ClearClassString properties
  • Integrate CSS builder for clear-icon styling
PopoverCompleteBase.cs
Update AutoComplete component to render and style clear icon
  • Extend razor markup to conditionally render clear-icon span
  • Add ClassString builder to include is-clearable class
  • Set default ClearIcon in OnParametersSet
AutoComplete.razor
AutoComplete.razor.cs
Enhance JavaScript to handle clear action
  • Register click handler on .clear-icon to clear input and trigger filter
  • Include el reference in dispose and unregister clear-icon click
AutoComplete.razor.js
Expand test coverage for clearable functionality
  • Add IsClearable_Ok unit test verifying clear-icon presence based on parameter
AutoCompleteTest.cs
Adjust sample and markup to demonstrate clearable feature
  • Cast localized description to MarkupString for correct rendering
  • Add IsClearable attribute to sample AutoComplete usage
AutoCompletes.razor

Assessment against linked issues

Issue Objective Addressed Explanation
#6732 Add a Clearable parameter to the AutoComplete component, which, when enabled and the input has a value, displays a clear button similar to the input component.
#6732 Ensure that when the clear button is shown, the original dropdown arrow is not displayed.
#6732 Update documentation and demo to show usage of the new Clearable parameter.

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

@bb-auto bb-auto bot added the enhancement New feature or request label Sep 18, 2025
@bb-auto bb-auto bot added this to the 9.10.0 milestone Sep 18, 2025
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 PR adds a clearable functionality to the AutoComplete component by introducing an IsClearable parameter. When enabled, it displays a clear icon button that allows users to clear the input value.

  • Adds IsClearable and ClearIcon parameters to enable/configure the clear functionality
  • Implements JavaScript event handling for the clear button click action
  • Updates test coverage and documentation to reflect the new clearable feature

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
PopoverCompleteBase.cs Adds IsClearable and ClearIcon parameters with supporting methods
AutoComplete.razor.cs Initializes ClearIcon and adds CSS class for clearable state
AutoComplete.razor Renders the clear icon conditionally based on IsClearable
AutoComplete.razor.js Implements click handler for clear functionality and cleanup
AutoCompleteTest.cs Adds unit test for IsClearable functionality
en-US.json, zh-CN.json Updates localization strings to mention the new feature
AutoCompletes.razor Demonstrates the clearable feature in the sample

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Sep 18, 2025
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 and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js:137-140` </location>
<code_context>
         EventHandler.on(document, 'keyup', ac.keyup);
     });
+
+    EventHandler.on(el, 'click', '.clear-icon', e => {
+        input.value = '';
+        invoke.invokeMethodAsync('TriggerFilter', '');
+    });
 }
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Consider preventing event propagation when clear icon is clicked.

Without stopping event propagation, clicking the clear icon may unintentionally trigger parent click handlers. Use `e.stopPropagation()` to prevent this.

```suggestion
    EventHandler.on(el, 'click', '.clear-icon', e => {
        e.stopPropagation();
        input.value = '';
        invoke.invokeMethodAsync('TriggerFilter', '');
    });
```
</issue_to_address>

### Comment 2
<location> `src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor:18-21` </location>
<code_context>
            placeholder="@PlaceHolder" disabled="@Disabled" @ref="FocusElement"/>
     <span class="form-select-append"><i class="@Icon"></i></span>
     <span class="form-select-append ac-loading"><i class="@LoadingIcon"></i></span>
+    @if (GetClearable())
+    {
+        <span class="@ClearClassString"><i class="@ClearIcon"></i></span>
+    }
     <RenderTemplate @ref="_dropdown">
</code_context>

<issue_to_address>
**suggestion:** Consider adding a role or aria-label for accessibility to the clear icon.

Since the clear icon is interactive, assigning a role of "button" and an appropriate aria-label will ensure it is accessible to screen readers.

```suggestion
    @if (GetClearable())
    {
        <span class="@ClearClassString" role="button" aria-label="Clear input" tabindex="0"><i class="@ClearIcon"></i></span>
    }
```
</issue_to_address>

### Comment 3
<location> `src/BootstrapBlazor/Components/AutoComplete/PopoverCompleteBase.cs:49-58` </location>
<code_context>
     [Parameter]
     public bool IsPopover { get; set; }

+    /// <summary>
+    /// Gets or sets whether the select component is clearable. Default is false.
+    /// </summary>
+    [Parameter]
+    public bool IsClearable { get; set; }
+
+    /// <summary>
+    /// Gets or sets the right-side clear icon. Default is fa-solid fa-angle-up.
+    /// </summary>
+    [Parameter]
+    [NotNull]
+    public string? ClearIcon { get; set; }
+
     /// <summary>
</code_context>

<issue_to_address>
**nitpick:** The default value in the summary for ClearIcon does not match the initialization logic.

Update the summary to accurately describe the default value, which is set by IconTheme.GetIconByKey(ComponentIcons.SelectClearIcon).
</issue_to_address>

### Comment 4
<location> `test/UnitTest/Components/AutoCompleteTest.cs:57-64` </location>
<code_context>
         Assert.Equal(2, menus.Count);
     }

+    [Fact]
+    public void IsClearable_Ok()
+    {
+        var cut = Context.RenderComponent<AutoComplete>();
+        Assert.DoesNotContain("clear-icon", cut.Markup);
+
+        cut.SetParametersAndRender(pb => pb.Add(a => a.IsClearable, true));
+        cut.Contains("clear-icon");
+    }
+
</code_context>

<issue_to_address>
**suggestion (testing):** Missing test for clearing input value and callback invocation.

Please add a test that simulates clicking the clear icon and asserts both the input value is cleared and the callback is invoked.
</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.

@codecov
Copy link

codecov bot commented Sep 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (47d21d5) to head (8e1c1d7).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6758   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          739       739           
  Lines        31713     31729   +16     
  Branches      4462      4466    +4     
=========================================
+ Hits         31713     31729   +16     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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(AutoComplete): 像input那样增加 Clearable 参数

2 participants