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

[BUG] overflow-y stop working when switching pages #218

Closed
luckashenri opened this issue Aug 24, 2023 · 10 comments
Closed

[BUG] overflow-y stop working when switching pages #218

luckashenri opened this issue Aug 24, 2023 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@luckashenri
Copy link

Describe the bug
Currently in my angular app, I added some routing inside the Drawer. Aka Cupertino Pane.
Everytime I move to another route the overflow-y stop working, like there's no scrolling.

At first I thought about recalculating and I found out that there's this method called 'calcFitHeight', but when I call it it says 'calcFitHeight is not a function'.

Second try was calling 'scrollElementInit'. That worked but only if I scroll DOWN. When I try to scroll UP again it brings the whole drawer with it.

https://github.com/luckashenri/cupertino-pane-bug

To Reproduce
Steps to reproduce the behavior:

  1. See my github project. Also dropped it in Stackblitz.

Expected behavior
When I switch page, it should recalculate and present the scroll like it does the first time I refresh. Or at least allow me to access some recalculate method.

Screenshots
image

Desktop:

  • OS: Windows
  • Browser [chrome]
  • Version 116.0.5845.98 (Official Build) (64-bit)

Additional context
Angular 16.2
No other library installed.
If I don't use overflow-y it works normally.

@roman-rr roman-rr self-assigned this Aug 24, 2023
@roman-rr roman-rr added the bug Something isn't working label Aug 24, 2023
@roman-rr
Copy link
Collaborator

@luckashenri not checked yet, just quick assumption that router remove elements from DOM. Maybe just init inside body will fix. I will check in few days.

@luckashenri
Copy link
Author

@roman-rr I tried with diff version, but still no luck.

Something interesting is that after calling 'scrollElementInit' it does work to scroll down, but when I scroll up it brings the panel together.

Well keep trying at the meantime and keep u posted.

@roman-rr
Copy link
Collaborator

@luckashenri Thank you again, I've checked.
calcFitHeight() method should be used for Auto Height panes with settings.fitHeight = true;
The fitHeight: true option will assign method calcFitHeight() for instance.

In your case, you just want to scroll up on each new page?

@luckashenri
Copy link
Author

luckashenri commented Aug 26, 2023

@roman-rr I found out something interesting..

Not sure if u're familiar with angular, or any other framework like that.. But basically when I put the 'overflow-y' attribute in a upper level, it will render the inner data correctly with scroll.

When I do it inside each inner page, it will work for first one only, and then break.

example 1:
image

In this example, the pages have their own custom header, and custom body. In that case, the scroll breaks cause it needs to recalc everytime I switch page (that's what I think).

example 2:

image

In this second example, I have the page changing INSIDE the overflow-y div.. In that case, even changing the height of inner content, it works nicely..
But in this case, I can't have a custom header like in first example.

@roman-rr
Copy link
Collaborator

roman-rr commented Aug 26, 2023

@luckashenri Would you like to recalculate height of overflow-y element on page changes?

  1. Have you tried setOverflowHeight() method ?
  2. Have you checked this example ? Here overflow element recalculated dynamically.

If nothing works, your example still relevant ? I may try to do this right on this example ? Or you have to adjust this example with headers ?

@luckashenri
Copy link
Author

@roman-rr .

I don't want the overflow-y to recalc it necessarely, it's just that I noticed that it loses the height once I move to another page for some reason, I thought recalculating would fix, but it caused the scroll affecting the drawer as well. (like I explain below answering ur second question).

1 - Yes, it didn't have any effect.
2 - Yes, I tried something similar calculating manually the height. It kinda works but then the action of scrolling inner scroll also affects the drawer as a whole. When I scroll it also drags the drawer.

Yeah that project I sent is still valid. In fact now I added 2 modules. One with it working (but with static header). And another with dynamic header (that comes within the page) but with scroll breaking.

Seems like stackblitz doesn't want to run it lol.. I guess u'll need to clone and run it. Lemme know if it works for u.

@luckashenri
Copy link
Author

luckashenri commented Aug 27, 2023

@roman-rr not sure it's relavant, but I noticed it shows 'cancelable: true' once it's being dragged.. The only difference I noticed so far between them.

not working example:
image

working example (I took this screenshot before switching pages, so I could check how was the states before breaking):
image

@roman-rr
Copy link
Collaborator

@luckashenri thank you for details, I'll check in couple days

@roman-rr
Copy link
Collaborator

@luckashenri Thank you for interesting case!
Actually, angular remove elements from DOM and all events also removed.
Moreover, for new element scroll have to be re-initialized and events re-attached.

Solution

Change your function to:

ngAfterViewInit() {
    this.router.events.pipe(
      filter(event => event instanceof NavigationEnd)
    ).subscribe({
      next: async (value) => {
        await new Promise(resolve => requestAnimationFrame(resolve));
        this.myPane.scrollElementInit();
        this.myPane.checkOverflowAttr(this.myPane.breakpoints.currentBreakpoint);
        this.myPane.events.detachAllEvents();
        this.myPane.events.attachAllEvents();
      },
    });
}

Not a simple case, if there are more such re-renders for overflow-y element in the future, I will make some scoped functions to manage events re-attachments around the scroll element.

@luckashenri
Copy link
Author

@roman-rr Yeah just got a chance to test it, it worked!!
I just ran some tests and profilers and seems like that won't have an impact on performance as well. Thanks man!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants