angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.39k stars 6.76k forks source link

Support blocking scroll on all scrolling containers via Overlay ScrollStrategy #10387

Open luke-emmental opened 6 years ago

luke-emmental commented 6 years ago

Bug, feature request, or proposal:

cdk overlayConfig scrollStrategies.block() not working

What is the expected behavior?

I expected It function block other scrollable at active overlay.

What is the current behavior?

Partially acted app serve -> working in only chrome prod build -> not working in any browser

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

os: macOS Sierra v:10.12.6 "@angular/animations": "5.2.8", "@angular/cdk": "5.2.4", "@angular/common": "5.2.8", "@angular/compiler": "5.2.8", "@angular/core": "5.2.8", "@angular/flex-layout": "^5.0.0-beta.13", "@angular/forms": "5.2.8", "@angular/material": "5.2.4", "@angular/material-moment-adapter": "5.2.4", "@angular/platform-browser": "5.2.8", "@angular/platform-browser-dynamic": "5.2.8", "@angular/router": "5.2.8", "core-js": "^2.4.1", "hammerjs": "^2.0.8", "rxjs": "^5.5.6", "web-animations-js": "^2.3.1", "zone.js": "^0.8.19" "@angular/compiler-cli": "5.2.8", "@angular/language-service": "5.2.8",

jstuth commented 6 years ago

I'm experiencing similar issues while setting scrollStrategy of a MatDialog. It just won't work.... i create my dialog the following way:

const dialogRef = this.dialog.open(EditAddressComponent, {
      panelClass: 'fullscreen-dialog-on-small-screens',
      data: this.company.address,
      scrollStrategy: this.overlay.scrollStrategies.block()
});

The background view is still scrolling. :(

jstuth commented 6 years ago

Somehow, the BlockScrollStrategy seem only to work, when window width is above 959px. Is this related to some media breakpoints, since 959px is exactly what i use?

croso-df commented 6 years ago

I'm having the same issues when using the cdk-connected-overlay as this:

<ng-template cdk-connected-overlay
              [cdkConnectedOverlayWidth]="200"
              [cdkConnectedOverlayOpen]="isOpened"
              [cdkConnectedOverlayOrigin]="overlayOrigin"
              [cdkConnectedOverlayPositions]="connectedOverlayPositions"
              [cdkConnectedOverlayScrollStrategy]="overlayScrollStrategy"
              (backdropClick)="closeItemsBlock()">

and then I set overlayScrollStrategy to:

this.overlayScrollStrategy = this.overlay.scrollStrategies.block();

The overlay will still allow scrolling though. My workaround was to enable the backdrop and remove the background color from the backdrop so that it doesn't render dark.

<ng-template cdk-connected-overlay
              [cdkConnectedOverlayWidth]="200"
              ...
              [cdkConnectedOverlayHasBackdrop]="true"
              cdkConnectedOverlayBackdropClass="foo-cdk-backdrop-class">

I know it looks like a nasty workaround, but well, makes the trick for now.

wojofe commented 6 years ago

Experiencing scroll propagation issues with MatDialog as well, in a somewhat erratic fashion even (resizing the browser window and re-opening the dialog produces differing results).

When I scroll down inside the dialog, the dialog scrolls to its end. When I scroll down inside the dialog again while the dialog is poised at its scroll-end, the page in the background scrolls. When I scroll outside the dialog, the page in the backgroud scrolls.

Opening a MatDialog with scrollStrategy: overlay.scrollStrategies.block() makes no difference at all.

mscudlik commented 6 years ago

same issue with mat-select, neither block() nor noop() stop the automatic scrolling

wojofe commented 5 years ago

Bump. Please make block() work again.

siddiq-rehman commented 5 years ago

It was working fine in v7.. Now it is not :(

mmalerba commented 4 years ago

Can someone provide a stackblitz example demonstrating this?

wagnermaciel commented 4 years ago

Closing because this issue has been inactive for 2 weeks or more after follow up was requested.

amaust82 commented 4 years ago

This is not working for me as well, here is a stackblitz showing an example of my issue.

Edit: Clarification that it is the issue I'm having, not necessarily the above examples.

blended-ideas commented 4 years ago

@wagnermaciel

Can we reopen this? Since a stackblitz issue has been given.,

jelbourn commented 4 years ago

@crisbeto it looks like the block scroll strategy only deals with top-level scrolling and not other scrolling containers on the page. Did we do that intentionally? I don't remember the reasoning from the time.

crisbeto commented 4 years ago

Yes, that was intentional since it was unclear what would happen if a scroll container was placed inside an overlay that blocks scrolling. Historically we didn't really need to block scroll on any other containers, because the overlay backdrop prevented users from interacting with the elements.

jelbourn commented 4 years ago

Got it. Since this is working at least as intended, I changed this issue to a feature request.

chitgoks commented 1 year ago

Pressing the page down or page up key does not block it. Bug?

zijianhuang commented 1 year ago

I have an overlay associated with a button and a popup mat-menu with another button inside a mat-dialog, And the content inside mat-dialog-content may cause a scrollbar inside the dialog.

When mat-menu is displayed, it can block the scrolling. However, when the overlay is shown, it does not block. And no matter what strategy I assigned to the overlay, the behaviour remains the same: noop.

private sso: ScrollStrategyOptions,
...

this.propertiesOverlayStrategy = sso.block();
<ng-template cdkConnectedOverlay
                     [cdkConnectedOverlayOrigin]="triggerTags"
                     [cdkConnectedOverlayOpen]="isTriggerTagsOpen"
                     [cdkConnectedOverlayScrollStrategy]="propertiesOverlayStrategy">
MartirosyanMarat commented 1 month ago

How to block the scroll? Solution

        [cdkConnectedOverlayHasBackdrop]="true"
        [cdkConnectedOverlayBackdropClass]="'smm-backdrop'"

As mentioned @croso-df we just need to add these 2 lines

Full code bellow

      <ng-template
        cdkConnectedOverlay
        [cdkConnectedOverlayOrigin]="moveShape"
        [cdkConnectedOverlayHasBackdrop]="true"
        [cdkConnectedOverlayBackdropClass]="'smm-backdrop'"
        [cdkConnectedOverlayScrollStrategy]="blockScrollStrategy"
        [cdkConnectedOverlayOpen]="toolbarState === ToolbarState.Move"
        (backdropClick)="setSection(ToolbarState.None)"
        (overlayOutsideClick)="setSection(ToolbarState.None)"
      >