Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Sep 2, 2025

Link issues

fixes #6708

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

Use JavaScript interop to update input values in AutoComplete, AutoFill, and Search components instead of Blazor bindings, and adjust initialization and tests accordingly.

Bug Fixes:

Enhancements:

  • Override InvokeInitAsync in AutoComplete, AutoFill, and Search to call JS init with component ID and initial value
  • Introduce a JS setValue function to update input.value for clear and selection actions
  • Remove @Bind attributes from input elements in AutoComplete, AutoFill, and Search to delegate value updates to JS

Tests:

  • Update AutoFill unit test to expect no static value attribute after JS interop takes over

Chores:

  • Remove redundant InvokeInitAsync override in PopoverCompleteBase

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

sourcery-ai bot commented Sep 2, 2025

Reviewer's Guide

This PR refactors the AutoComplete, AutoFill, and Search components to update their input elements’ values via JavaScript interop instead of Blazor two-way binding, introducing a new setValue JS function, adjusting initialization methods, and removing direct @Bind attributes to avoid binding conflicts.

Sequence diagram for input value update via JavaScript in AutoComplete, AutoFill, and Search

sequenceDiagram
    participant BlazorComponent as Blazor Component
    participant JSInterop as JS Interop
    participant JS as JavaScript
    BlazorComponent->>JSInterop: InvokeVoidAsync("setValue", Id, value)
    JSInterop->>JS: setValue(id, value)
    JS->>JS: input.value = value
Loading

Class diagram for updated AutoComplete, AutoFill, and Search components

classDiagram
    class AutoComplete {
        +Task InvokeInitAsync()
        +Task OnClickItem(string val)
    }
    class AutoFill {
        +Task InvokeInitAsync()
        +Task OnClearValue()
        +Task OnClickItem(TValue val)
    }
    class Search {
        +Task InvokeInitAsync()
        +Task OnClearClick()
        +Task OnClickItem(TValue val)
    }
    AutoComplete --|> ComponentBase
    AutoFill --|> ComponentBase
    Search --|> ComponentBase
Loading

File-Level Changes

Change Details Files
Added JS-based input value updates
  • Invoke setValue via InvokeVoidAsync on clear and item click handlers
  • Implement protected override Task InvokeInitAsync() to call JS init with current display text/value
AutoFill.razor.cs
Search.razor.cs
AutoComplete.razor.cs
Introduced setValue function in JavaScript
  • Export setValue(id, value) to update the input element’s value
  • Hook into existing component data registry
AutoComplete.razor.js
Removed direct @Bind bindings from Razor templates
  • Delete @bind attributes on input elements in AutoComplete, AutoFill, and Search
  • Rely solely on JS interop for value synchronization
AutoComplete.razor
AutoFill.razor
Search.razor
Updated unit test expectations for input value
  • Change assertion to expect null input value attribute after clearing
AutoFillTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#6708 Update the input value in the AutoComplete component using JavaScript instead of Blazor's @Bind mechanism.

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

Updates AutoComplete components to use JavaScript for input value management instead of Blazor data binding, addressing issue #6708.

  • Removes @bind directives from input elements in AutoComplete, AutoFill, and Search components
  • Adds JavaScript setValue function and corresponding C# method calls for programmatic value updates
  • Updates unit tests to reflect that input values are no longer bound through HTML attributes

Reviewed Changes

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

Show a summary per file
File Description
test/UnitTest/Components/AutoFillTest.cs Updates test assertion to expect null value attribute
src/BootstrapBlazor/Components/Search/Search.razor.cs Adds JavaScript setValue calls and InvokeInitAsync override
src/BootstrapBlazor/Components/Search/Search.razor Removes @Bind directive from input element
src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs Adds JavaScript setValue calls and InvokeInitAsync override
src/BootstrapBlazor/Components/AutoFill/AutoFill.razor Removes @Bind directive from input element
src/BootstrapBlazor/Components/AutoComplete/PopoverCompleteBase.cs Removes base InvokeInitAsync method
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js Implements setValue JavaScript function
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs Adds JavaScript setValue calls and InvokeInitAsync override
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor Removes @Bind directive from input element

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:

  • Since you removed the Razor @Bind on the inputs, double-check that your JS init logic still wires up input events to update the .NET state so user typing flows back into CurrentValue.
  • There’s a lot of repeated InvokeVoidAsync("setValue", …) calls across components – consider extracting a shared helper or base method to avoid duplication.
  • Confirm that dropping the InvokeInitAsync override in PopoverCompleteBase doesn’t regress popover autocomplete initialization.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Since you removed the Razor @bind on the inputs, double-check that your JS init logic still wires up input events to update the .NET state so user typing flows back into CurrentValue.
- There’s a lot of repeated InvokeVoidAsync("setValue", …) calls across components – consider extracting a shared helper or base method to avoid duplication.
- Confirm that dropping the InvokeInitAsync override in PopoverCompleteBase doesn’t regress popover autocomplete initialization.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js:178` </location>
<code_context>
     }
 }

+export function setValue(id, value) {
+    const ac = Data.get(id)
+    const { input } = ac;
+    if (input) {
+        input.value = value;
+    }
+}
+
</code_context>

<issue_to_address>
Consider handling cases where Data.get(id) or ac.input is undefined.

If either is undefined, consider logging a warning or handling the case explicitly to improve debuggability.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
export function setValue(id, value) {
    const ac = Data.get(id)
    const { input } = ac;
    if (input) {
        input.value = value;
    }
}
=======
export function setValue(id, value) {
    const ac = Data.get(id);
    if (!ac) {
        console.warn(`AutoComplete: No entry found for id '${id}' in Data.`);
        return;
    }
    const { input } = ac;
    if (!input) {
        console.warn(`AutoComplete: No input found for id '${id}'.`);
        return;
    }
    input.value = value;
}
>>>>>>> REPLACE

</suggested_fix>

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 2, 2025

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6709   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          739       739           
  Lines        31706     31713    +7     
  Branches      4462      4462           
=========================================
+ Hits         31706     31713    +7     
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 f9fda76 into main Sep 2, 2025
6 checks passed
@ArgoZhang ArgoZhang deleted the feat-auto branch September 2, 2025 06:03
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): use javascript update input value

2 participants