Skip to content

Fix/overlay accumulate margins#2701

Open
SebayK wants to merge 4 commits intoing-bank:masterfrom
SebayK:fix/overlay-accumulate-margins
Open

Fix/overlay accumulate margins#2701
SebayK wants to merge 4 commits intoing-bank:masterfrom
SebayK:fix/overlay-accumulate-margins

Conversation

@SebayK
Copy link
Contributor

@SebayK SebayK commented Feb 9, 2026

#2349

  1. Move body margin management from OverlayController to OverlaysManager
    singleton to prevent margin accumulation when multiple overlays with
    preventsScroll:true are shown.

The manager now tracks how many overlays are preventing scroll via a
counter. Only the first overlay captures and compensates body margin;
subsequent overlays increment the counter without modifying margin.
When hiding, only the last overlay restores the original margin.

Add regression test that demonstrates issue ing-bank#2349 - when multiple
overlays with preventsScroll:true are shown, body margins should not
accumulate. Currently this test fails, showing the bug exists.

Related to ing-bank#2349
Move body margin management from OverlayController to OverlaysManager
singleton to prevent margin accumulation when multiple overlays with
preventsScroll:true are shown.

The manager now tracks how many overlays are preventing scroll via a
counter. Only the first overlay captures and compensates body margin;
subsequent overlays increment the counter without modifying margin.
When hiding, only the last overlay restores the original margin.

This aligns with existing scroll-lock class management and follows the
pattern recommended in issue ing-bank#2349.

Fixes ing-bank#2349
Copilot AI review requested due to automatic review settings February 9, 2026 14:19
@changeset-bot
Copy link

changeset-bot bot commented Feb 9, 2026

⚠️ No Changeset found

Latest commit: 32c437d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

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 addresses Issue #2349 by moving body margin compensation for preventsScroll: true overlays from OverlayController into the OverlaysManager singleton, aiming to prevent margin accumulation when multiple scroll-preventing overlays are nested.

Changes:

  • Centralize body size/margin compensation logic in OverlaysManager and introduce a counter to avoid repeated margin adjustments for nested preventsScroll overlays.
  • Update OverlayController to delegate body size keeping to the manager (including during teardown).
  • Add/adjust tests to verify non-accumulating margins for nested scroll-preventing overlays and to validate teardown behavior.

Reviewed changes

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

File Description
packages/ui/components/overlays/test/OverlayController.test.js Adds regression coverage for nested preventsScroll margin behavior and updates tests to reflect manager-owned margin state.
packages/ui/components/overlays/src/OverlaysManager.js Introduces counter-based centralized body margin compensation via requestToKeepBodySize().
packages/ui/components/overlays/src/OverlayController.js Removes per-controller margin handling and delegates to OverlaysManager; adds teardown-phase delegation.

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

Address review feedback to fix edge cases where teardown() could cause
negative counter values and break margin restoration:

1. Add guard to only decrement __preventScrollCount when > 0
2. Gate _keepBodySize('teardown') behind isShown check to prevent
   unbalanced decrements when teardown() is called on hidden overlays
3. Add tests for teardown() and updateConfig() on hidden overlays

These changes ensure the counter stays balanced even when:
- teardown() is called on never-shown overlays
- updateConfig() internally calls teardown() on hidden overlays
- teardown() is called after hide() has already run

Addresses review comments in ing-bank#2701
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants