-
-
Notifications
You must be signed in to change notification settings - Fork 362
feat(AutoFill): add IsAutoClearWhenInvalid parameter #6950
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
input输入Enter时,如候选项唯一,直接选中 当焦点从AutoFill移出时,如GetDisplayText(Value)对应的内容与input中的内容不符则清空Value和Input
Signed-off-by: braia123 <[email protected]>
Reviewer's GuideIntroduces 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 IsAutoClearWhenInvalidsequenceDiagram
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
Class diagram for updated AutoFill component with IsAutoClearWhenInvalidclassDiagram
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()
}
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 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
IsAutoClearWhenInvalidparameter to AutoFill component with auto-clear functionality on blur - Refactors
TriggerBlurStringproperty 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.
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/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>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 #6950 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 740 740
Lines 31875 31891 +16
Branches 4469 4472 +3
=========================================
+ Hits 31875 31891 +16
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 #6949
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
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:
Enhancements:
Documentation:
Tests: