Skip to content
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

feat(FloatingLabel): add OnBlurAsync parameter #4523

Merged
merged 9 commits into from
Oct 24, 2024
Merged

Conversation

ArgoZhang
Copy link
Collaborator

@ArgoZhang ArgoZhang commented Oct 24, 2024

add OnBlurAsync parameter

Summary of the changes (Less than 80 chars)

简单描述你更改了什么, 不超过80个字符;如果有关联 Issue 请在下方填写相关编号

Description

fixes #4522

Regression?

  • Yes
  • No

[If yes, specify the version the behavior has regressed from]

[是否影响老版本]

Risk

  • High
  • Medium
  • Low

[Justify the selection above]

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

Add the OnBlurAsync parameter to the BootstrapInputBase class to support asynchronous operations on input blur events, and refactor the FloatingLabel component to use this new parameter.

New Features:

  • Introduce the OnBlurAsync parameter to handle asynchronous operations when the input loses focus.

Enhancements:

  • Refactor the OnBlur method to utilize the new OnBlurAsync parameter for handling blur events.

Summary by CodeRabbit

  • New Features

    • Introduced a new OnBlurAsync property in the BootstrapInputBase class, allowing users to specify a callback for when the input loses focus.
    • Added event handling for the blur event in the FloatingLabel component to enhance user interaction.
  • Bug Fixes

    • Removed outdated OnBlurAsync functionality from multiple components, simplifying user input handling.
  • Refactor

    • Updated OnBlur methods across various components to improve event handling and accessibility.

Copy link

sourcery-ai bot commented Oct 24, 2024

Reviewer's Guide by Sourcery

The PR moves the OnBlurAsync parameter and its implementation from BootstrapInput to BootstrapInputBase (its parent class) and adds the onblur event handler to the FloatingLabel component. This change allows the blur functionality to be shared across different input components that inherit from BootstrapInputBase.

Sequence diagram for OnBlurAsync event handling

sequenceDiagram
    participant User as User
    participant FloatingLabel as FloatingLabel
    participant BootstrapInputBase as BootstrapInputBase
    User->>FloatingLabel: Focus out (blur event)
    FloatingLabel->>BootstrapInputBase: Call OnBlur()
    BootstrapInputBase->>BootstrapInputBase: Check OnBlurAsync
    alt OnBlurAsync is not null
        BootstrapInputBase->>BootstrapInputBase: Execute OnBlurAsync(Value)
    end
Loading

File-Level Changes

Change Details Files
Relocated OnBlurAsync parameter and implementation to base class
  • Removed OnBlurAsync parameter from BootstrapInput
  • Removed OnBlur method implementation from BootstrapInput
  • Added OnBlurAsync parameter to BootstrapInputBase
  • Added OnBlur method implementation to BootstrapInputBase
src/BootstrapBlazor/Components/Input/BootstrapInput.razor.cs
src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs
Added blur event handling to FloatingLabel component
  • Added @OnBlur event binding to the input element
src/BootstrapBlazor/Components/Input/FloatingLabel.razor

Assessment against linked issues

Issue Objective Addressed Explanation
#4522 Add OnBlurAsync parameter to FloatingLabel component

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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 enhancement New feature or request label Oct 24, 2024
@bb-auto bb-auto bot added this to the v8.10.0 milestone Oct 24, 2024
Copy link

coderabbitai bot commented Oct 24, 2024

Walkthrough

The pull request involves significant changes to the BootstrapInput and BootstrapInputBase classes within the BootstrapBlazor.Components namespace. The OnBlurAsync property and its associated method OnBlur have been removed from the BootstrapInput<TValue> class, simplifying its functionality regarding blur events. Conversely, the BootstrapInputBase<TValue> class has introduced a new OnBlurAsync property and method, allowing for asynchronous handling of blur events. Additionally, the FloatingLabel component has been updated to include an event handler for the blur event.

Changes

File Path Change Summary
src/BootstrapBlazor/Components/Input/BootstrapInput.razor.cs Removed OnBlurAsync property and OnBlur method from BootstrapInput<TValue>.
src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs Added OnBlurAsync property and OnBlur method to BootstrapInputBase<TValue>.
src/BootstrapBlazor/Components/Input/FloatingLabel.razor Added @onblur event handler to the <input> element, binding it to the @OnBlur method.
src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs Removed OnBlurAsync parameter and updated OnBlur method to override base implementation.
src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs Updated OnBlur method to override base implementation and call OnBlurAsync if defined.
src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs Removed OnBlurAsync parameter and updated OnBlur method to override base implementation.
src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs Removed OnBlurAsync property and OnBlur method from Textarea component.

Assessment against linked issues

Objective Addressed Explanation
Add OnBlurAsync parameter in FloatingLabel (4522)

Possibly related issues

Possibly related PRs

Poem

🐰 In fields of code where inputs play,
A blur event has found its way.
With async calls, we hop and cheer,
For focus lost brings functions near.
A change so bright, let’s celebrate,
In Blazor's garden, we create! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Oct 24, 2024
Copy link

@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 and they look great!

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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs (1)

87-91: Enhance XML documentation for OnBlurAsync.

While the property declaration follows the established pattern, the documentation could be more descriptive to help developers understand its purpose and usage.

Consider expanding the documentation like this:

     /// <summary>
-    /// 获得/设置 失去焦点回调方法 默认 null
+    /// 获得/设置 失去焦点回调方法
+    /// <para>当输入框失去焦点时触发的异步回调方法</para>
+    /// <para>参数为当前输入值,默认为 null</para>
     /// </summary>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0afbc41 and f699dc7.

📒 Files selected for processing (3)
  • src/BootstrapBlazor/Components/Input/BootstrapInput.razor.cs (0 hunks)
  • src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs (2 hunks)
  • src/BootstrapBlazor/Components/Input/FloatingLabel.razor (1 hunks)
💤 Files with no reviewable changes (1)
  • src/BootstrapBlazor/Components/Input/BootstrapInput.razor.cs
🔇 Additional comments (3)
src/BootstrapBlazor/Components/Input/FloatingLabel.razor (1)

6-6: LGTM! Consider updating documentation.

The addition of @onblur="@OnBlur" correctly implements the async blur functionality by binding to the base class handler.

Let's check if the documentation needs updating:

✅ Verification successful

Let me try a different approach to verify the documentation needs by searching for any documentation files that might reference floating labels or input components.


Let me try one final verification to check if there are any documentation files in the repository root or component directories that might need updating.


Based on the verification results, I can now provide the final response:

The change is correct, no documentation updates required

The @onblur binding addition to FloatingLabel component is correct, and after thorough verification:

  • No component-specific documentation exists that needs updating
  • The only documentation file (docs/repro.md) is for bug reporting guidelines
  • The component inherits the functionality from BootstrapInputBase, which already has the documentation for this feature
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Look for documentation files that might need updating
# Test: Search for FloatingLabel documentation
fd -e md -e mdx FloatingLabel

Length of output: 31


Script:

#!/bin/bash
# Search for documentation files in common doc directories
fd -e md -e mdx . docs src/BootstrapBlazor/docs

# Search for any documentation mentioning FloatingLabel or input components
rg -i "floatinglabel|floating label|input component" -g "*.{md,mdx}"

# Check if there's a README in the component directory
find src/BootstrapBlazor/Components/Input -name "README.md"

Length of output: 265


Script:

#!/bin/bash
# Check content of docs/repro.md to see if it's relevant
cat docs/repro.md

# Search for any documentation in the Components directory
fd -e md -e mdx . src/BootstrapBlazor/Components

# Look for any API documentation patterns
rg -i "onblur|floating.*label" README.md || true

Length of output: 2151

src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs (2)

200-209: LGTM! Implementation follows established patterns.

The OnBlur method implementation is well-structured:

  • Follows the async/await pattern
  • Includes null check before callback invocation
  • Allows customization in derived classes through the virtual modifier
  • Maintains consistency with other callback implementations in the class

200-209: Verify blur event binding in FloatingLabel component.

Let's ensure the FloatingLabel component correctly binds to this new OnBlur method.

✅ Verification successful

Let me try a different approach to verify the blur event binding and component integration.


Based on the search results, I can now provide a conclusive response:

Blur event binding is correctly implemented across input components

The verification shows that:

  • The FloatingLabel component (src/BootstrapBlazor/Components/Input/FloatingLabel.razor) correctly binds to the OnBlur method using @onblur="@OnBlur" in its template.
  • This implementation is consistent with other input components in the codebase that inherit from BootstrapInputBase.
  • The blur event binding pattern is uniformly implemented across related components:
    • FloatingLabel.razor
    • BootstrapInput.razor
    • AutoComplete.razor
    • InputNumber.razor
    • Search.razor
    • Textarea.razor
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for blur event binding in FloatingLabel component
echo "Searching for blur event binding in FloatingLabel component..."
rg -l "FloatingLabel" | xargs rg "@onblur|@bind-OnBlur|@onclick:blur" -A 2 -B 2

Length of output: 214


Script:

#!/bin/bash
# First, let's find all files containing FloatingLabel
echo "Files containing FloatingLabel:"
fd . -t f | xargs rg -l "FloatingLabel"

# Then search for Razor component files with blur event handling
echo -e "\nSearching for blur event handling in Razor files:"
fd . -t f -e razor | xargs rg "@onblur|@bind-OnBlur|@onclick:blur" -A 2 -B 2

# Look for the base input component implementation
echo -e "\nSearching for Input component implementation:"
rg -l "BootstrapInputBase" | xargs rg "protected override async Task OnAfterRenderAsync|protected override void BuildRenderTree"

Length of output: 6543

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 4 lines in your changes missing coverage. Please review.

Project coverage is 99.98%. Comparing base (0afbc41) to head (bae9551).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...tstrapBlazor/Components/AutoFill/AutoFill.razor.cs 0.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main    #4523      +/-   ##
===========================================
- Coverage   100.00%   99.98%   -0.02%     
===========================================
  Files          631      631              
  Lines        27070    27065       -5     
  Branches      3927     3927              
===========================================
- Hits         27070    27061       -9     
- Misses           0        3       +3     
- Partials         0        1       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs (1)

265-268: Consider adding error handling for JS interop.

The InvokeVoidAsync call could throw an exception if the JS interop fails. Consider wrapping it in a try-catch block to handle potential failures gracefully.

     if (NullableUnderlyingType != null && string.IsNullOrEmpty(CurrentValueAsString))
     {
         // set component value empty
-        await InvokeVoidAsync("clear", Id);
+        try
+        {
+            await InvokeVoidAsync("clear", Id);
+        }
+        catch (JSException ex)
+        {
+            // Log the error or handle it appropriately
+            Logger.LogWarning(ex, "Failed to clear input value via JS interop");
+        }
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f699dc7 and bae9551.

📒 Files selected for processing (4)
  • src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs (1 hunks)
  • src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs (1 hunks)
  • src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs (1 hunks)
  • src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs (0 hunks)
💤 Files with no reviewable changes (1)
  • src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs
🔇 Additional comments (2)
src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs (2)

Line range hint 191-191: LGTM: Improved backward compatibility.

The change from collection expression syntax to explicit List initialization enhances compatibility with older C# versions while maintaining the same functionality.


142-156: Consider adding null check for Value parameter in OnBlurAsync.

The implementation looks good overall, but there are two points to consider:

  1. The Value parameter passed to OnBlurAsync should have a null check to prevent potential null reference issues.
  2. Verify if executing OnBlurAsync after OnSelectedItemChanged is the intended order, as it might affect dependent operations.

@ArgoZhang ArgoZhang merged commit 420f7f7 into main Oct 24, 2024
5 of 7 checks passed
@ArgoZhang ArgoZhang deleted the feat-floating branch October 24, 2024 04:34
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(FloatingLabel): add OnBlurAsync parameter
1 participant