Skip to content

bug(MATERIAL): Close Scroll Strategy is triggered by scroll behavior within the overlay #26780

Closed
@yalquorashy

Description

@yalquorashy

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

I was working on a bug related to dropdowns moving around the screen when a scroll happens within its parent container. The proposed solution was to add a cdkScrollable directive and a 'close' Scroll Strategy to the dropdown component used.
A potential bug in Angular Material was discovered where if two nested scrollable containers exist (i.e. an overlay containing a cdk-virtual-scroll-viewport component within a scrollable window), the global scrollDispatcher would get triggered if a scroll within the dropdown occurs and this would cause the dropdown to close. Consequently, the user would never be able to scroll within the dropdown without abruptly closing it. The proposed solution for this was to inject a local scrollDispatcher instance in the overlay service, and the scroll event fired from the dropdown would not trigger the close scroll strategy.
Finally, once the dropdown is closed on outside scroll, the dropdown search field should be unfocused, and for that, .detachments() was called in the overlay service.

Reproduction

https://stackblitz.com/edit/angular-ru7qdi-tbavjg?file=src%2Fapp%2Fcdk-overlay-basic-example.html,src%2Fapp%2Fapp.module.ts,src%2Fapp%2Fcdk-overlay-basic-example.ts,src%2Fapp%2Fcdk-overlay-basic-example.css,package.json

Expected Behavior

The local Scroll Dispatcher instance would not be needed and scrolling within the dropdown would not trigger the closing scroll strategy, since the scroll strategy is related to scroll behavior outside of the overlay and not within it (see: https://material.angular.io/cdk/overlay/overview#scroll-strategies)

image

Actual Behavior

Scrolling within the dropdown overlay causes it to close.

Environment

  • Angular: 15.0.0
  • CDK/Material: 15.0.0
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/overlay

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions