Skip to content

bug(Drawer): AllowResize not work#7365

Merged
ArgoZhang merged 4 commits intomainfrom
fix-drawer
Dec 18, 2025
Merged

bug(Drawer): AllowResize not work#7365
ArgoZhang merged 4 commits intomainfrom
fix-drawer

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Dec 18, 2025

Link issues

fixes #7364

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

Bug Fixes:

  • Ensure the Drawer resize handle is found among the drawer body children so AllowResize works reliably when the bar is not a direct descendant of the root element.

Copilot AI review requested due to automatic review settings December 18, 2025 07:57
@bb-auto bb-auto bot added the bug Something isn't working label Dec 18, 2025
@bb-auto bb-auto bot added this to the v10.1.0 milestone Dec 18, 2025
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Dec 18, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts how the resizable bar element is located within the Drawer component so that AllowResize works correctly when the .drawer-bar is not a direct descendant of the root element, and updates disposal logic accordingly.

Flow diagram for Drawer bar selection in initDrag and dispose

flowchart TD
  A[initDrag called with el] --> B[Select drawerBody using selector .drawer-body]
  B --> C[Find bar by iterating drawerBody children and checking class drawer-bar]
  C --> D{bar found?}
  D -->|Yes| E[Attach Drag.drag handlers to bar]
  D -->|No| F[Skip drag initialization]

  subgraph DisposeFlow
    G[dispose called with id] --> H[Select el by id]
    H --> I[Select drawerBody using selector .drawer-body]
    I --> J[Find bar by iterating drawerBody children and checking class drawer-bar]
    J --> K{bar found?}
    K -->|Yes| L[Call Drag.dispose on bar]
    K -->|No| M[No drag disposal needed]
  end
Loading

File-Level Changes

Change Details Files
Change Drawer drag handle lookup to search within the drawer body children instead of querying the entire element for .drawer-bar.
  • In the Drawer initialization, replace el.querySelector('.drawer-bar') with a search over drawerBody.children for an element containing the drawer-bar class.
  • Maintain and reuse the drawerBody reference to determine orientation and compute size while using the found bar as the drag handle.
src/BootstrapBlazor/Components/Drawer/Drawer.razor.js
Align dispose logic to use the same drawer-body-scoped search for the resizable bar before calling Drag.dispose.
  • In the dispose method, introduce a drawerBody reference and locate the .drawer-bar by scanning its direct children for the drawer-bar class.
  • Guard Drag.dispose with the new bar lookup so cleanup only runs when a drag handle exists.
src/BootstrapBlazor/Components/Drawer/Drawer.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#7364 Fix the Drawer component so that the AllowResize feature works correctly, including when drawers are nested.

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

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Dec 18, 2025
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 there - I've reviewed your changes - here's some feedback:

  • Both in initDrag and dispose, the new logic assumes drawerBody is always found; consider null-guarding drawerBody before accessing .children to avoid potential runtime errors when the structure is not as expected.
  • You repeat the same drawerBody/bar lookup logic in initDrag and dispose; consider extracting this into a small helper function to keep the behavior consistent and reduce duplication.
  • By restricting the bar lookup to direct children of .drawer-body, any existing structure where .drawer-bar is nested deeper will now stop working; if backward compatibility is needed, you might want to fallback to the previous querySelector('.drawer-bar') when the direct-child search fails.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Both in `initDrag` and `dispose`, the new logic assumes `drawerBody` is always found; consider null-guarding `drawerBody` before accessing `.children` to avoid potential runtime errors when the structure is not as expected.
- You repeat the same `drawerBody`/`bar` lookup logic in `initDrag` and `dispose`; consider extracting this into a small helper function to keep the behavior consistent and reduce duplication.
- By restricting the bar lookup to direct children of `.drawer-body`, any existing structure where `.drawer-bar` is nested deeper will now stop working; if backward compatibility is needed, you might want to fallback to the previous `querySelector('.drawer-bar')` when the direct-child search fails.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/Drawer/Drawer.razor.js:12` </location>
<code_context>
     let isVertical = false;
     const drawerBody = el.querySelector('.drawer-body');
-    const bar = el.querySelector('.drawer-bar');
+    const bar = [...drawerBody.children].find(i => i.classList.contains('drawer-bar'));
     Drag.drag(bar,
         e => {
</code_context>

<issue_to_address>
**issue (bug_risk):** Guard against `drawerBody` being null before accessing `.children`.

This change now assumes `el.querySelector('.drawer-body')` always returns an element. If `.drawer-body` is missing, `drawerBody` will be `null` and `[...drawerBody.children]` will throw. Please add a null check (e.g., early return or conditional/optional chaining) before accessing `drawerBody.children`.
</issue_to_address>

### Comment 2
<location> `src/BootstrapBlazor/Components/Drawer/Drawer.razor.js:11-12` </location>
<code_context>
     let height = 0;
     let isVertical = false;
     const drawerBody = el.querySelector('.drawer-body');
-    const bar = el.querySelector('.drawer-bar');
+    const bar = [...drawerBody.children].find(i => i.classList.contains('drawer-bar'));
     Drag.drag(bar,
         e => {
</code_context>

<issue_to_address>
**issue:** Apply the same null-safety for `drawerBody` in `dispose` as in `initDrag`.

Because `dispose` now assumes `.drawer-body` always exists, `drawerBody` could be `null` if the child is removed or markup changes, causing a runtime error when spreading `children`. Add a null check before accessing `drawerBody.children` to make the disposal path resilient to these cases.
</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.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 18, 2025

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7365   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          747       747           
  Lines        32760     32760           
  Branches      4540      4540           
=========================================
  Hits         32760     32760           
Flag Coverage Δ
BB 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.

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 fixes a bug where the AllowResize functionality in the Drawer component was not working correctly. The issue was that the original code used querySelector which could find the wrong drawer-bar element when there are nested drawers, causing the resize feature to malfunction.

Key Changes:

  • Updated selector logic in both initDrag and dispose functions to search for drawer-bar only among direct children of drawerBody, preventing conflicts with nested drawer elements
  • Removed BOM character and trailing whitespace for code cleanup

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(Drawer): AllowResize not work

2 participants