Skip to content

feat(Drawer): add CloseAsync method#7506

Merged
ArgoZhang merged 3 commits intomainfrom
feat-drawer
Jan 13, 2026
Merged

feat(Drawer): add CloseAsync method#7506
ArgoZhang merged 3 commits intomainfrom
feat-drawer

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Jan 13, 2026

Link issues

fixes #7490

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

Add an asynchronous close operation to drawer options and wire it through the drawer container, updating tests to cover the new behavior.

New Features:

  • Expose a CloseAsync method on DrawerOption to programmatically close a drawer instance.

Enhancements:

  • Capture and store a Drawer component reference in DrawerOption via DrawerContainer to support programmatic control.

Tests:

  • Extend drawer service tests to verify that invoking DrawerOption.CloseAsync triggers the configured close callback.
  • Remove the obsolete direct Drawer.Close test in favor of exercising the new CloseAsync flow through DrawerOption.

Copilot AI review requested due to automatic review settings January 13, 2026 05:02
@bb-auto bb-auto bot added the enhancement New feature or request label Jan 13, 2026
@bb-auto bb-auto bot added this to the v10.2.0 milestone Jan 13, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Jan 13, 2026

Reviewer's Guide

Adds an async-close capability to Drawer via DrawerOption.CloseAsync, wires Drawer instance into DrawerOption at render time, and updates tests to validate closing through the option instead of directly on the Drawer component.

Sequence diagram for DrawerOption.CloseAsync interaction

sequenceDiagram
    actor Caller
    participant DrawerOption
    participant Drawer

    Caller->>DrawerOption: CloseAsync()
    activate DrawerOption
    alt Drawer instance is set
        DrawerOption->>Drawer: Close()
        activate Drawer
        Drawer-->>DrawerOption: completed Task
        deactivate Drawer
    else Drawer instance is null
        DrawerOption-->>Caller: return completed Task
    end
    DrawerOption-->>Caller: completed Task
    deactivate DrawerOption
Loading

Updated class diagram for DrawerOption and Drawer relationship

classDiagram
    class DrawerOption {
        int? ZIndex
        internal Drawer Drawer
        Task CloseAsync()
    }

    class Drawer {
        Task Close()
    }

    class DrawerContainer {
        void RenderDrawer(RenderTreeBuilder builder, DrawerOption option)
    }

    DrawerOption --> Drawer : holds_reference
    DrawerContainer --> DrawerOption : configures
    DrawerContainer ..> Drawer : renders
Loading

Flow diagram for DrawerContainer RenderDrawer component reference capture

flowchart TD
    A[RenderDrawer called with DrawerOption] --> B[Create Drawer component]
    B --> C[Apply parameters from DrawerOption]
    C --> D[Capture component reference]
    D --> E[Set option.Drawer to Drawer instance]
    E --> F[DrawerOption.CloseAsync can call Drawer.Close]
Loading

File-Level Changes

Change Details Files
Add CloseAsync method on DrawerOption that delegates closing to the underlying Drawer component instance.
  • Introduce internal Drawer property on DrawerOption to hold the rendered Drawer instance.
  • Implement public async CloseAsync on DrawerOption that calls Drawer.Close() when the Drawer instance is available.
src/BootstrapBlazor/Components/Drawer/DrawerOption.cs
Wire the rendered Drawer component instance back into DrawerOption during rendering.
  • Use AddComponentReferenceCapture in DrawerContainer.RenderDrawer to capture the Drawer instance.
  • Assign the captured instance to option.Drawer so that DrawerOption.CloseAsync can operate on it.
src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs
Update unit tests to validate closing through DrawerOption.CloseAsync and remove obsolete direct close test on Drawer.
  • Extend DrawerServiceTest.Show_Ok to configure JSInterop, set an OnCloseAsync handler on DrawerOption, invoke option.CloseAsync, and assert the close callback ran.
  • Remove the DrawerTest.Close_Ok test that directly invoked Drawer.Close(), as closing is now exercised through DrawerOption.
test/UnitTest/Services/DrawerServiceTest.cs
test/UnitTest/Components/DrawerTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#7490 Add a public async close method on DrawerOption (analogous to DialogOption.CloseDialogAsync) to allow programmatic closing of a Drawer.
#7490 Wire DrawerOption to the underlying Drawer component so that calling the new close method actually closes the drawer, and add tests to verify this behavior.

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
Copy Markdown
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 - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/Drawer/DrawerOption.cs:96-101` </location>
<code_context>
+    /// <summary>
+    /// 关闭抽屉弹窗方法
+    /// </summary>
+    public async Task CloseAsync()
+    {
+        if (Drawer != null)
+        {
+            await Drawer.Close();
+        }
+    }
 }
</code_context>

<issue_to_address>
**suggestion (performance):** Avoid unnecessary async state machine allocation in `CloseAsync` when only forwarding to `Drawer.Close()`.

Since this method only forwards to `Drawer?.Close()`, you can remove `async/await` and return the task directly:

```csharp
public Task CloseAsync() => Drawer?.Close() ?? Task.CompletedTask;
```

This keeps the API unchanged while avoiding the async state machine allocation and extra overhead when `Drawer` is null.
</issue_to_address>

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.

Comment thread src/BootstrapBlazor/Components/Drawer/DrawerOption.cs
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 13, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7506   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          748       748           
  Lines        32978     32986    +8     
  Branches      4583      4584    +1     
=========================================
+ Hits         32978     32986    +8     
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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ArgoZhang ArgoZhang disabled auto-merge January 13, 2026 05:08
@ArgoZhang ArgoZhang merged commit e1858d6 into main Jan 13, 2026
9 of 10 checks passed
@ArgoZhang ArgoZhang deleted the feat-drawer branch January 13, 2026 05:09
Copy link
Copy Markdown
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 adds a CloseAsync method to the DrawerOption class, enabling programmatic closing of drawers through the option object. This enhancement provides a cleaner API for consumers who need to close drawers without direct access to the Drawer component instance.

Changes:

  • Added CloseAsync() public method and internal Drawer property to DrawerOption
  • Updated DrawerContainer to capture the Drawer component reference and assign it to the option
  • Replaced direct Drawer component test with a more comprehensive service-level test that validates the new API

Reviewed changes

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

File Description
src/BootstrapBlazor/Components/Drawer/DrawerOption.cs Added CloseAsync method and internal Drawer property to enable programmatic drawer closing
src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs Added component reference capture to link DrawerOption with Drawer instance
test/UnitTest/Components/DrawerTest.cs Removed redundant Close_Ok test that directly tested Drawer.Close()
test/UnitTest/Services/DrawerServiceTest.cs Added comprehensive test for CloseAsync functionality through DrawerService

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

internal Drawer? Drawer { get; set; }

/// <summary>
/// 关闭抽屉弹窗方法
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The documentation comment uses Chinese text ("关闭抽屉弹窗方法") which is inconsistent with other documentation in the file that uses English. For consistency with the codebase style, this should be in English, such as "Closes the drawer".

Suggested change
/// 关闭抽屉弹窗方法
/// Closes the drawer.

Copilot uses AI. Check for mistakes.
button = cut.Find("button");
await cut.InvokeAsync(() => button.Click());

// 测试 Option 关闭方法
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The test comment uses Chinese text ("测试 Option 关闭方法") which is inconsistent with the rest of the test file that uses English comments. For consistency and maintainability, this should be in English, such as "Test Option CloseAsync method".

Suggested change
// 测试 Option 关闭方法
// Test Option CloseAsync method

Copilot uses AI. Check for mistakes.
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(Drawer): add CloseAsync method

2 participants