-
-
Notifications
You must be signed in to change notification settings - Fork 362
fix(AutoComplete): support bind-Value/OnValueChanged callback #6792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideAdds 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
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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.
There was a problem hiding this 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #6787
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
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:
Enhancements:
Tests: