bug(MATERIAL): Close Scroll Strategy is triggered by scroll behavior within the overlay #26780
Labels
area: cdk/overlay
P3
An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Is this a regression?
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)
Actual Behavior
Scrolling within the dropdown overlay causes it to close.
Environment
The text was updated successfully, but these errors were encountered: