ng-sidebar icon indicating copy to clipboard operation
ng-sidebar copied to clipboard

Scroll bar appears under fixed div

Open adama357 opened this issue 7 years ago • 8 comments

We've been using ng-sidebar for awhile now, and for the most part it works well. However, since the beginning we have had this problem:

We have a fixed div taking up the entire page width at the top (a header bar), and the browser's scrollbar appears underneath the div. (The desired behavior is for the scrollbar to appear along the entire right side of the page, not to have it overlapping with the page contents.) After a quick search, I learned that the problem arises from a page body's overflow settings. In this case, it was being caused by the ng-sidebar page structure.

The exact code has had to change a few times as we've updated ng-sidebar, but as of v. 6.0.0, the get-around code is as follows:

ng-sidebar-container {
    overflow: inherit !important;   // hidden by default
}

.ng-sidebar__content {
    overflow: inherit !important;  // auto by default
}

But with the latest version, this hacky solution introduces a new problem: The sidebar is stuck at the top of the page, so if you scroll down and open the sidebar, you'll see the bottom of the sidebar and backdrop. You're able to scroll the page freely while the sidebar's open. (Removing the above CSS fixes these problems.)

I'll try to see if there's additional CSS I can add to the sidebar to get rid of this problem. But in the meantime, I just thought I'd let you know about this problem in case there's some way to get around it.

Thanks!

adama357 avatar Jun 28 '17 17:06 adama357

By adding this CSS code, I'm able to keep the sidebar on the screen:

.ng-sidebar__backdrop[_ngcontent-c0] {
    position: fixed !important;
}

.ng-sidebar[_ngcontent-c1] {
    position: fixed !important;
}

Even after setting [trapFocus]="true", I wasn't able to find a way to stop the page from scrolling while the sidebar's open (much less of a problem). I assume that's why the overflow was set to hidden in the first place.

adama357 avatar Jun 29 '17 16:06 adama357

Any update on this?

Teebo avatar Mar 19 '20 08:03 Teebo

I am looking for a solution as well

tatjana-arthronica avatar Mar 25 '20 18:03 tatjana-arthronica

Hi @tatjana-arthronica, please let me know if you did manage to come up with something, I will also keep you posted

Teebo avatar Mar 27 '20 07:03 Teebo

Hi @tatjana-arthronica, please let me know if you did manage to come up with something, I will also keep you posted

Hi @Teebo, my temporary solution is setting fixed element's width on page load and on window resize (it is fixed header in my case). Let me know if you need to see example code.

tatjana-arthronica avatar Mar 27 '20 12:03 tatjana-arthronica

Hi @tatjana-arthronica, thank you for the response, yes please share your code if possible.

Teebo avatar Apr 01 '20 14:04 Teebo

@tatjana-arthronica I have also figured in out, your approach helped me, thanks!

Teebo avatar Apr 03 '20 12:04 Teebo

In app.component.html

  • add above to ng-sidebar-content <div #inner ng-sidebar-content>

  • add above to router-outlet <router-outlet (activate)="onActivate($event)"> </router-outlet>

In app.component.ts

 @ViewChild('inner') inner: ElementRef;
  onActivate(event) {
    this.inner.nativeElement.parentElement.scrollTop = 0;
    }

Just try this you can solve the problem


buddhikadesilva avatar May 19 '21 20:05 buddhikadesilva