Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Apr 17, 2025

Link issues

fixes #5837

Summary By Copilot

This pull request enhances the AutoComplete component in the BootstrapBlazor library by adding support for a new OnBlurAsync callback and improving the handling of blur events. Key changes include updates to the Razor, C#, and JavaScript files to implement this functionality.

Enhancements to blur event handling:

  • Razor file update (AutoComplete.razor): Removed the @onblur attribute from the Razor markup to centralize blur event handling through JavaScript and the new OnBlurAsync callback.

  • C# backend logic (AutoComplete.razor.cs): Added a check in the OnClickItem method to invoke the OnBlurAsync callback if it is defined, ensuring that blur events are triggered programmatically as needed.

  • JavaScript enhancements (AutoComplete.razor.js):

    • Updated the init function to include the input element in the ac object for easier access.
    • Introduced a new blur method in the ac object to handle blur events and invoke the TriggerBlur method on the C# side when the data-bb-blur attribute is set to true.
    • Replaced the keyup handler with a more specific implementation to ensure proper handling of the Tab key and blur events.
  • C# component base class (PopoverCompleteBase.cs): Added a TriggerBlur method marked with [JSInvokable] to allow JavaScript to invoke the OnBlurAsync callback when triggered.

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

Refactor the AutoComplete component to improve blur event handling and add support for an OnBlurAsync callback

New Features:

  • Added OnBlurAsync callback to trigger blur events programmatically

Enhancements:

  • Centralized blur event handling through JavaScript and a new OnBlurAsync callback
  • Improved input element access and event management in the AutoComplete component

Chores:

  • Removed direct @OnBlur attribute from Razor markup
  • Updated JavaScript event handling to support more precise blur triggers

@ArgoZhang ArgoZhang requested a review from Copilot April 17, 2025 02:27
@bb-auto bb-auto bot added the enhancement New feature or request label Apr 17, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Apr 17, 2025

Reviewer's Guide by Sourcery

This pull request refactors the AutoComplete component to enhance blur event handling and introduce a new OnBlurAsync callback. The changes involve updates to Razor, C#, and JavaScript files to centralize blur event handling through JavaScript and improve input element management.

Sequence diagram for blur event handling in AutoComplete

sequenceDiagram
    participant User
    participant AutoComplete.razor
    participant AutoComplete.razor.js
    participant PopoverCompleteBase.cs

    User->AutoComplete.razor: Clicks outside AutoComplete
    activate AutoComplete.razor
    AutoComplete.razor->AutoComplete.razor.js: blur()
    activate AutoComplete.razor.js
    AutoComplete.razor.js->AutoComplete.razor.js: Check data-bb-blur attribute
    alt data-bb-blur is true
        AutoComplete.razor.js->PopoverCompleteBase.cs: invokeMethodAsync('TriggerBlur')
        activate PopoverCompleteBase.cs
        PopoverCompleteBase.cs->PopoverCompleteBase.cs: OnBlurAsync(Value)
        PopoverCompleteBase.cs-->>AutoComplete.razor.js: 
        deactivate PopoverCompleteBase.cs
    end
    AutoComplete.razor.js-->>AutoComplete.razor: 
    deactivate AutoComplete.razor.js
    deactivate AutoComplete.razor
Loading

File-Level Changes

Change Details Files
Introduced a new OnBlurAsync callback and improved handling of blur events in the AutoComplete component.
  • Added support for a new OnBlurAsync callback.
  • Improved the handling of blur events.
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js
src/BootstrapBlazor/Components/AutoComplete/PopoverCompleteBase.cs
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs
test/UnitTest/Components/AutoCompleteTest.cs
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor
Centralized blur event handling through JavaScript and the new OnBlurAsync callback.
  • Removed the @onblur attribute from the Razor markup.
  • Implemented JavaScript-triggered blur event handling.
  • Added a TriggerBlur method marked with [JSInvokable] to allow JavaScript to invoke the OnBlurAsync callback when triggered.
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js
src/BootstrapBlazor/Components/AutoComplete/PopoverCompleteBase.cs
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor
Improved input element management in the AutoComplete component.
  • Updated the init function to include the input element in the ac object for easier access.
  • Replaced the keyup handler with a more specific implementation to ensure proper handling of the Tab key and blur events.
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#5837 Update the blur logic of the AutoComplete component.

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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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 this to the v9.5.0 milestone Apr 17, 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 refactors the AutoComplete component’s blur handling to support a new OnBlurAsync callback and centralizes blur event logic.

  • Removed the @OnBlur attribute from the Razor markup
  • Added a JSInvokable TriggerBlur method in the C# component base class
  • Updated the JavaScript to include the input element and separate blur and keyup handlers

Reviewed Changes

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

File Description
src/BootstrapBlazor/Components/AutoComplete/PopoverCompleteBase.cs Adds TriggerBlur method to allow JS to invoke the OnBlurAsync callback
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js Updates initialization to include the input element and refactors the blur/keyUp handlers
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs Calls OnBlurAsync in OnClickItem to trigger blur events programmatically
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor Removes the @OnBlur attribute in favor of JavaScript-based blur handling
Comments suppressed due to low confidence (1)

src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs:134

  • Potential double invocation of OnBlurAsync may occur when an item is clicked since the callback is invoked both in OnClickItem and via JavaScript's TriggerBlur; please confirm that this behavior is intentional or add checks to avoid duplicate execution.
if (OnBlurAsync != null)

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Apr 17, 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 @ArgoZhang - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a debounce to the TriggerBlur method to avoid excessive calls to the OnBlurAsync callback.
  • It might be cleaner to pass the id of the component to the blur function in javascript, rather than using this.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

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 refactors the AutoComplete component to improve blur event handling and add an OnBlurAsync callback.

  • Adds a JS-invokable TriggerBlur method in the C# component base class.
  • Updates the JavaScript file to centralize blur handling and ensures the callback is invoked during keyup events and popover close events.
  • Removes the direct @OnBlur binding from the Razor markup to rely solely on JavaScript for blur management.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/BootstrapBlazor/Components/AutoComplete/PopoverCompleteBase.cs Added TriggerBlur for JS-triggered blur callbacks.
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js Updated event listeners to call the new blur method.
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs Updated OnClickItem to invoke OnBlurAsync if defined.
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor Removed the @OnBlur attribute to centralize blur handling.

@ArgoZhang
Copy link
Member Author

@sourcery-ai review

@codecov
Copy link

codecov bot commented Apr 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (6e64c22) to head (f6460f3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #5838   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          660       660           
  Lines        30105     30123   +18     
  Branches      4251      4255    +4     
=========================================
+ Hits         30105     30123   +18     

☔ 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.

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Apr 17, 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 @ArgoZhang - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The javascript changes look good, but I'm concerned about the duplication of the OnBlurAsync call in OnClickItem and TriggerBlur.
  • Consider debouncing the OnBlurAsync event to avoid excessive calls.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

@ArgoZhang ArgoZhang disabled auto-merge April 17, 2025 03:00
@ArgoZhang ArgoZhang merged commit 4fce242 into main Apr 17, 2025
5 checks passed
@ArgoZhang ArgoZhang deleted the refactor-blur branch April 17, 2025 03:01
ArgoZhang added a commit that referenced this pull request Apr 17, 2025
* refactor: update blur event callback

* refactor: 更新脚本

* test: 更新单元测试

* refactor: 增加 Blur 支持

* test: 增加单元测试
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.

refactor(AutoComplete): update blur logic

2 participants