Skip to content
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

Scroll events not getting fired when content inside md-content is scrolled #802

Closed
ghostofcain opened this issue Jul 2, 2016 · 13 comments
Closed
Assignees
Labels
needs: discussion Further discussion with the team is needed before proceeding

Comments

@ghostofcain
Copy link

ghostofcain commented Jul 2, 2016

Bug, feature request, or proposal:

Bug

What is the expected behavior?

When you scroll the page and the md-content's height is larger than the available space, page scroll events should be fired.

What is the current behavior?

They don't get fired.

Please note, this was working correctly in the alpha5 version but now it's broken in v2.0.0.-alpha6.

To add further information, consider this to be the layout:

<md-sidenav-layout>
    <md-sidenav #sidenav>
        <md-nav-list>
            ...
    </md-sidenav>
    <md-toolbar style="background-color: #2db1eb; color: white">
            ...
    </md-toolbar>
    <router-outlet></router-outlet>
</md-sidenav-layout>

When the content placed inside is larger than the available height, the scroll events are not firing. This is preventing me from implementing infinite scroll on various components.

Can you please let me know if there is a workaround for this?

Many thanks,

@mrusful
Copy link

mrusful commented Jul 9, 2016

Looks like #703 change behavior.
scroll event fires by md-content.

As a workaround, i think, you can wrap all what not in md-sidenav into div and listen scroll event on it.

<div (scroll)="handleScroll($event.target)" style="height: 100%; overflow: auto;">
    <md-toolbar style="background-color: #2db1eb; color: white">
        ...
    </md-toolbar>
    <router-outlet></router-outlet>
</div>

@karser
Copy link

karser commented Apr 10, 2017

overflow: auto; doesn't look good, so it's not an option.
An alternative solution is to not use fullscreen on md-sidenav-layout. Some CSS tweaks help, although, if I set body { height:100%; } it also breaks document:scroll event listener.

@matte00
Copy link

matte00 commented Jun 1, 2017

I confirm it, without fullscreen it's works. So if you want have scroll content insiede sidenav you could use scroll event on div content. For example:

<md-sidenav-container fullscreen>
    <md-sidenav align="start" #drleft>
    </md-sidenav>
    <div layout="column" layout-fill>    
      <div flex layout="column" class="content md-content" (scroll)="onScroll($event)">
        put here your scrollable data
      </div>
    </div>
  </md-sidenav-container>

@twoheaded
Copy link

Looks like something wrong with it. I have no idea how to handle scroll event in my app with md-sidenav.
Plunker

@willshowell
Copy link
Contributor

@twoheaded Here's one way to do it https://plnkr.co/edit/BjOKFrP5mNOdVI8d2EKl?p=preview

@mmalerba would it be possible to expose the Scrollable instance? That would give user's the ability to subscribe to elementScrolled() instead of having to use document.querySelector()

@twoheaded
Copy link

@willshowell Thanks again! The solution though working, but not very pretty as for me. It's bad that the ability to handle scroll events by the native Angular way is lost

@mmalerba
Copy link
Contributor

@willshowell I'm currently looking into how to make the sidenav work better for mobile use cases (where people typically want a fixed position sidenav and the scroll events get fired on the body, so that the browser chrome will scroll out of view). I'll think about this too while I'm prototyping. What if we just give developers control of the content element? That seems like the easiest solution to this issue. For example:

<md-sidenav-container>
  <md-sidenav>My sidenav</md-sidenav>
  <md-sidenav-content (scroll)="...">My content</md-sidenav-content>
</md-sidenav-container>

@willshowell
Copy link
Contributor

@mmalerba IMO that sounds more versatile and I like that it's a little more prescriptive

@twoheaded
Copy link

It seems to me that there is some shortcoming in sidenav architecture. I do not understand why the side navigation should wrap a content and override properties and behavior of main container. IMO sidenav should be in the container next to other content, rather than around it. For exemple md-toolbar doesn't wrap main content. Because of this, there are problems with scrolling and positioning of elements.

jp-hoehmann added a commit to jp-hoehmann/aldo that referenced this issue Aug 6, 2017
This does not look quite as ugly and allows me to observe scroll events.
It still won't hide the browser chrome on mobile, but it will do while
I am waiting for angular/components#802.
@jelbourn
Copy link
Member

@mmalerba can we close this now that fixed sidenav is in master?

@mmalerba
Copy link
Contributor

yep, fixed sidenav is in now, and docs are coming in #7775

@ghost
Copy link

ghost commented Mar 2, 2018

Thank you @mrusful for leading me on the way.

I had no success using the scroll events, been looking for an hour, and you gave me the hint to put my scroll event on my mat-sidenav-content element (I wanted scroll events on my content).

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
@mmalerba mmalerba added the needs: discussion Further discussion with the team is needed before proceeding label Mar 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: discussion Further discussion with the team is needed before proceeding
Projects
None yet
Development

No branches or pull requests

8 participants