-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug(Sidenav+Tabs+Drag n drop): Drag scroll not working if Sidenav-Content height set to 100vh #18737
bug(Sidenav+Tabs+Drag n drop): Drag scroll not working if Sidenav-Content height set to 100vh #18737
Comments
i think this can be handled from the application end, |
Thanks for the suggestion. Edit: Just implemented my suggested workaround. Works fine but involves major changes in the app layout structure. Thats not so nice. |
To some degree, this doesn't have anything to do with the sidenav or tab components. The main issue with your demo is you're trying to scroll an element that is not the One solution is to manually register the sidenav content as a scrollable parent of the droplist - something like this: @ViewChild(MatSidenavContent , {read: ElementRef}) sideNavContentElement: ElementRef;
@ViewChild(CdkDropList) dropList: CdkDropList;
ngAfterViewInit() {
// register the sidenav content as a scrollable parent element
if (this.sideNavContentElement) {
this.dropList._dropListRef.withScrollableParents([this.sideNavContentElement.nativeElement])
}
} https://stackblitz.com/edit/angular-ebzjz5-ftwbai?file=src%2Fapp%2Fexpansion-overview-example.ts If you have a statically-defined number of droplists/sidenav contents then this is fine, but it's not a very scalable solution. This pull request added the ability to define scrollable containers other than the droplist and window by adding a <mat-sidenav-content style="max-height: 100vh" cdkScrollable>
...
</mat-sidenav-content> and the drop list would "automatically" pick up this element as a scrollable parent. Unfortunately, this doesn't work with your use case, because the drop list is projected (multiple levels) inside the sidenav content and registering the cdkScrollables happens inside the /** Returns all registered Scrollables that contain the provided element. */
getAncestorScrollContainers(elementRef: ElementRef): CdkScrollable[] {
const scrollingContainers: CdkScrollable[] = [];
this.scrollContainers.forEach((_subscription: Subscription, scrollable: CdkScrollable) => {
if (this._scrollableContainsElement(scrollable, elementRef)) {
scrollingContainers.push(scrollable);
}
});
return scrollingContainers;
} will return an empty list of scrollContainers, despite your HTML actually having a You can find ways to get around this...for example, if not using Ivy, you can override CdkDropList.prototype.ngAfterViewInit = function(){
// @breaking-change 11.0.0 Remove null check for _scrollDispatcher once it's required.
if (this._scrollDispatcher) {
setTimeout(() => {const scrollableParents = this._scrollDispatcher
.getAncestorScrollContainers(this.element)
.map(scrollable => scrollable.getElementRef().nativeElement);
this._dropListRef.withScrollableParents(scrollableParents);
})
}
} But really, I think the best solution is to use CdkDropList.prototype.ngAfterViewInit = function(){
// @breaking-change 11.0.0 Remove null check for _scrollDispatcher once it's required.
if (this._scrollDispatcher) {
const scrollableParents = this._scrollDispatcher
.getAncestorScrollContainers(this.element)
.map(scrollable => scrollable.getElementRef().nativeElement);
this._dropListRef.withScrollableParents(scrollableParents);
}
} Using Example here: @crisbeto thoughts on switching the |
Currently we resolve a drop list's scrollable parents inside `ngAfterViewInit`, but this might be too early if the element is being projected. These changes move the logic to the first time the user starts dragging which should guarantee that the DOM structure has settled. Fixes angular#18737.
Thanks. In which version will this fix be released? |
It'll be in the next patch release. |
…18918) Currently we resolve a drop list's scrollable parents inside `ngAfterViewInit`, but this might be too early if the element is being projected. These changes move the logic to the first time the user starts dragging which should guarantee that the DOM structure has settled. Fixes #18737. (cherry picked from commit 3e984c7)
Released with Material 9.2.1 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Reproduction
https://stackblitz.com/edit/angular-ebzjz5?file=src%2Fapp%2Fexpansion-overview-example.html
Steps to reproduce:
Expected Behavior
The view autoscrolls while draging the item to the bottom of the screen.
Actual Behavior
It doesn't autoscoll.
It does if i either delete the tab-group or if i delete the max-height of 100vh of the sidenav-content.
Please take a look at the stackblitz.
Environment
A possible workaround could be to delete the height of 100vh and set items in the sidenav to a fixed position so they are always visible. Not testet though.
The text was updated successfully, but these errors were encountered: