Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Sep 27, 2025

Link issues

fixes #6787

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

Support bind-value/OnValueChanged callback in AutoComplete by tracking client value, extending JS interop to handle change events, and synchronizing value updates between client and server

New Features:

  • Enable two-way binding for AutoComplete via ValueChanged/OnValueChanged callbacks

Enhancements:

  • Synchronize client-side input value with server-side Value property on re-render via OnAfterRenderAsync and setValue JS interop
  • Enhance JS init to accept initial value and an optional change callback to invoke TriggerChange on input changes

Tests:

  • Add unit test to verify BindValue functionality for both OnValueChanged and ValueChanged delegates

Copilot AI review requested due to automatic review settings September 27, 2025 05:10
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 27, 2025

Reviewer's Guide

Adds bidirectional binding support for the AutoComplete component by tracking client-side value changes, syncing server-to-client updates, wiring a JS change event callback, and verifying behavior with unit tests.

File-Level Changes

Change Details Files
Introduce client-side value tracking and sync logic
  • Add private _clientValue field and initialize it in OnInitialized
  • Implement OnAfterRenderAsync to detect server Value changes and call setValue via JS interop
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs
Wire in change callback for value binding
  • Extend InvokeInitAsync to pass a callback name if OnValueChanged or ValueChanged is set
  • Add GetChangedEventCallbackName helper
  • Implement JSInvokable TriggerChange to update CurrentValueAsString and _clientValue
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs
Enhance JavaScript init to support value setting and change events
  • Update init signature to accept initial value and callback name
  • Set input.value on initialization
  • Attach input 'change' event to invoke .NET callback when provided
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js
Add unit test for bind-Value and change callback behavior
  • Create BindValue_Ok test to verify TriggerChange invokes OnValueChanged and ValueChanged
test/UnitTest/Components/AutoCompleteTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#6787 Restore two-way data binding functionality for AutoComplete component when IsClearable parameter is used.
#6787 Trigger OnValueChanged event when the clear button is clicked and the value is cleared.

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 bug Something isn't working label Sep 27, 2025
@bb-auto bb-auto bot added this to the 9.10.0 milestone Sep 27, 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 fixes issue #6787 by adding support for bind-Value and OnValueChanged callback functionality in the AutoComplete component, enabling two-way data binding.

Key changes:

  • Added client-side change event handling to detect when the input value changes
  • Implemented server-side callback methods to handle value changes and maintain synchronization
  • Added comprehensive unit tests to verify the two-way binding functionality

Reviewed Changes

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

File Description
AutoComplete.razor.js Added change event listener and value initialization to support client-side value changes
AutoComplete.razor.cs Implemented TriggerChange method and value synchronization logic for two-way binding
AutoCompleteTest.cs Added unit test to verify bind-Value and OnValueChanged callback functionality

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 27, 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.cs:148-153` </location>
<code_context>
+    {
+        await base.OnAfterRenderAsync(firstRender);
+
+        if (!firstRender)
+        {
+            if (Value != _clientValue)
+            {
+                _clientValue = Value;
+                await InvokeVoidAsync("setValue", Id, _clientValue);
+            }
+        }
</code_context>

<issue_to_address>
**issue (bug_risk):** Potential for unnecessary setValue invocation if Value and _clientValue are both null.

Since _clientValue is initialized as an empty string, comparing it to Value may not correctly handle nulls. Use string.Equals with StringComparison or explicitly check for null to prevent unnecessary JS interop calls.
</issue_to_address>

### Comment 2
<location> `src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js:67-71` </location>
<code_context>
         }
     });

+    if (changedEventCallback) {
+        EventHandler.on(input, 'change', e => {
+            invoke.invokeMethodAsync(changedEventCallback, e.target.value);
+        });
+    }
+
</code_context>

<issue_to_address>
**suggestion:** Using 'change' event may not capture all input scenarios.

Consider handling the 'input' event for real-time updates, as 'change' only triggers on blur after a value change.

```suggestion
    if (changedEventCallback) {
        EventHandler.on(input, 'input', e => {
            invoke.invokeMethodAsync(changedEventCallback, e.target.value);
        });
    }
```
</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 27, 2025

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6792   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          739       739           
  Lines        31721     31739   +18     
  Branches      4464      4467    +3     
=========================================
+ Hits         31721     31739   +18     
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 7051bf1 into main Sep 27, 2025
7 checks passed
@ArgoZhang ArgoZhang deleted the fix-auto branch September 27, 2025 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(AutoComplete): v9.10.2 增加 IsClearable 参数后,数据双向绑定无效

2 participants