Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Oct 19, 2025

Link issues

fixes #6949

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

Introduce IsAutoClearWhenInvalid to AutoFill to automatically clear invalid values on blur by tracking client input via JS interop and invoking a before-blur hook, updating related components, tests, and samples.

New Features:

  • Add IsAutoClearWhenInvalid parameter to AutoFill to optionally clear invalid inputs on blur.

Enhancements:

  • Introduce JS interop via TriggerChange and OnBeforeBlurAsync hook in PopoverCompleteBase to support auto-clearing logic.
  • Include TriggerBlur attribute on AutoFill, AutoComplete, and Search components to enable blur handling interop.

Documentation:

  • Update AutoFills sample to demonstrate the IsAutoClearWhenInvalid parameter.

Tests:

  • Add unit test verifying the IsAutoClearWhenInvalid behavior in AutoFill.

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

sourcery-ai bot commented Oct 19, 2025

Reviewer's Guide

Introduces an IsAutoClearWhenInvalid parameter to AutoFill that clears the bound value when the user leaves the input with an invalid entry, backed by JS interop and a new OnBeforeBlurAsync hook, and covered by unit tests and sample updates.

Sequence diagram for AutoFill blur event with IsAutoClearWhenInvalid

sequenceDiagram
    participant User as actor User
    participant AutoFill
    participant JS as "JavaScript"
    User->>AutoFill: Enter value in input
    JS->>AutoFill: TriggerChange(value) (on input change)
    User->>AutoFill: Blur input (leave field)
    JS->>AutoFill: TriggerBlur()
    AutoFill->>AutoFill: OnBeforeBlurAsync()
    alt IsAutoClearWhenInvalid && value is invalid
        AutoFill->>AutoFill: CurrentValue = default
        AutoFill->>JS: setValue(Id, "")
    end
Loading

Class diagram for updated AutoFill component with IsAutoClearWhenInvalid

classDiagram
    class AutoFill_TValue {
        +bool IsAutoClearWhenInvalid
        +string _clientValue
        +void TriggerChange(string v)
        +override async Task OnBeforeBlurAsync()
    }
    AutoFill_TValue --|> PopoverCompleteBase_TValue
    class PopoverCompleteBase_TValue {
        +virtual Task OnBeforeBlurAsync()
    }
Loading

File-Level Changes

Change Details Files
Implement IsAutoClearWhenInvalid behavior in AutoFill
  • Add IsAutoClearWhenInvalid parameter and its XML doc
  • Expose TriggerBlurString when OnBlurAsync or auto‐clear is enabled
  • Capture client‐side input via JSInvokable TriggerChange
  • Override OnBeforeBlurAsync to clear invalid entries and update the DOM
  • Adjust InvokeInitAsync to wire up TriggerChange callback
AutoFill.razor.cs
AutoFill.razor
Introduce OnBeforeBlurAsync hook in PopoverCompleteBase
  • Define virtual OnBeforeBlurAsync method
  • Invoke OnBeforeBlurAsync before existing blur logic
PopoverCompleteBase.cs
Propagate blur trigger flag to other components
  • Add TriggerBlurString property to AutoComplete
  • Add TriggerBlurString property to Search
AutoComplete.razor.cs
Search.razor.cs
Cover auto‐clear behavior with unit tests
  • Add IsAutoClearWhenInvalid_Ok test that toggles the flag and verifies value clearing
AutoFillTest.cs
Update sample to demonstrate new parameter
  • Enable IsAutoClearWhenInvalid in AutoFills.razor example
AutoFills.razor

Assessment against linked issues

Issue Objective Addressed Explanation
#6949 Add an IsAutoClearWhenInvalid parameter to the AutoFill component.
#6949 Implement logic so that when IsAutoClearWhenInvalid is true, the input is automatically cleared if the value is invalid.
#6949 Add or update tests and documentation/demos to cover the new IsAutoClearWhenInvalid 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

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 new IsAutoClearWhenInvalid parameter to the AutoFill component that automatically clears the input value when the user enters invalid text and then blurs the field. The feature tracks client-side input changes and compares them with the display text of the bound value on blur.

  • Introduces IsAutoClearWhenInvalid parameter to AutoFill component with auto-clear functionality on blur
  • Refactors TriggerBlurString property from base class to individual components for more granular control
  • Adds comprehensive test coverage for the new auto-clear behavior

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs Adds IsAutoClearWhenInvalid parameter, TriggerChange method to track client input, and OnBeforeBlurAsync override to implement auto-clear logic
src/BootstrapBlazor/Components/AutoFill/AutoFill.razor Updates data attributes to include blur trigger based on new parameter
src/BootstrapBlazor/Components/AutoComplete/PopoverCompleteBase.cs Removes TriggerBlurString property and adds OnBeforeBlurAsync virtual method to support pre-blur hooks
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs Re-implements TriggerBlurString property locally after removal from base class
src/BootstrapBlazor/Components/Search/Search.razor.cs Re-implements TriggerBlurString property locally after removal from base class
src/BootstrapBlazor.Server/Components/Samples/AutoFills.razor Demonstrates the new IsAutoClearWhenInvalid parameter in the sample
test/UnitTest/Components/AutoFillTest.cs Adds test case IsAutoClearWhenInvalid_Ok to verify auto-clear behavior works correctly

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 Oct 19, 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/AutoFill/AutoFill.razor.cs:195-199` </location>
<code_context>
+    /// <param name="v"></param>
+    /// <returns></returns>
+    [JSInvokable]
+    public void TriggerChange(string v)
+    {
+        _clientValue = v;
+    }
</code_context>

<issue_to_address>
**suggestion:** TriggerChange is not async; consider making it async for future extensibility.

Returning Task now will make it easier to add async operations later without changing the method signature, which is important for JSInvokable methods.

```suggestion
    [JSInvokable]
    public async Task TriggerChange(string v)
    {
        _clientValue = v;
        await Task.CompletedTask;
    }
```
</issue_to_address>

### Comment 2
<location> `src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs:306-310` </location>
<code_context>
+    /// <returns></returns>
+    protected override async Task OnBeforeBlurAsync()
+    {
+        if (IsAutoClearWhenInvalid && GetDisplayText(Value) != _clientValue)
+        {
+            CurrentValue = default;
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Comparison between GetDisplayText(Value) and _clientValue may be culture or whitespace sensitive.

Normalize or trim both values before comparison to prevent mismatches caused by culture, casing, or whitespace differences.

```suggestion
        if (IsAutoClearWhenInvalid &&
            !string.Equals(
                GetDisplayText(Value)?.Trim(),
                _clientValue?.Trim(),
                StringComparison.OrdinalIgnoreCase))
        {
            CurrentValue = default;
            await InvokeVoidAsync("setValue", Id, "");
        }
```
</issue_to_address>

### Comment 3
<location> `src/BootstrapBlazor/Components/AutoComplete/PopoverCompleteBase.cs:180-183` </location>
<code_context>
+    /// 触发 OnBlurAsync 回调前回调方法
+    /// </summary>
+    /// <returns></returns>
+    protected virtual Task OnBeforeBlurAsync() => Task.CompletedTask;
+
     /// <summary>
</code_context>

<issue_to_address>
**suggestion:** OnBeforeBlurAsync is virtual; document or enforce invocation order in derived classes.

When overriding, clarify whether base.OnBeforeBlurAsync() must be called, or enforce this requirement in documentation or implementation.

```suggestion
    /// <summary>
    /// 触发 OnBlurAsync 回调前回调方法
    /// <para>
    /// 当派生类重写此方法时,必须调用 <c>base.OnBeforeBlurAsync()</c> 以确保正确的调用顺序。
    /// </para>
    /// </summary>
    /// <returns></returns>
    /// <remarks>
    /// Derived classes overriding this method <b>must</b> call <c>base.OnBeforeBlurAsync()</c> to ensure correct invocation order.
    /// </remarks>
    protected virtual Task OnBeforeBlurAsync() => Task.CompletedTask;
```
</issue_to_address>

### Comment 4
<location> `test/UnitTest/Components/AutoFillTest.cs:516-525` </location>
<code_context>
+    [Fact]
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding tests for edge cases such as null or empty input values.

Please add tests for null, empty, and case-insensitive input values to ensure comprehensive coverage.
</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 Oct 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (337f129) to head (36849cd).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6950   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          740       740           
  Lines        31875     31891   +16     
  Branches      4469      4472    +3     
=========================================
+ Hits         31875     31891   +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.

@ArgoZhang ArgoZhang merged commit 0addc2f into main Oct 19, 2025
5 checks passed
@ArgoZhang ArgoZhang deleted the feat-auto-fill branch October 19, 2025 02:41
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): add IsAutoClearWhenInvalid parameter

3 participants