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

switching nav scrolls to the top of the page #3900

Closed
jnizet opened this issue Nov 13, 2020 · 2 comments · Fixed by #3936
Closed

switching nav scrolls to the top of the page #3900

jnizet opened this issue Nov 13, 2020 · 2 comments · Fixed by #3936

Comments

@jnizet
Copy link
Member

jnizet commented Nov 13, 2020

In a page where there is some text at the top, not filing the whole viewport height, and a nav at the bottom, large enough for the page to scroll, if you scroll down, then switch to another tab, the browser scrolls back to the top of the page.
This happens with or without animation, and with or without destroyOnHide.

bug-nav

Bug description:

Link to minimally-working StackBlitz that reproduces the issue:

https://stackblitz.com/edit/angular-hyx6po?file=src%2Findex.html

Versions of Angular, ng-bootstrap and Bootstrap:

Angular: 10 / 11

ng-bootstrap: 8.0.0

Bootstrap: 4.5.3

@maxokorokov
Copy link
Member

Indeed. Looks like for a brief period of time between fade out and fade in the outlet stays empty.

I suspect (just a guess) something is wrong around this ngIf:

<ng-template ngFor let-item [ngForOf]="nav.items">
<div ngbNavPane *ngIf="item.isPanelInDom() || isPanelTransitioning(item)" [item]="item" [nav]="nav" [role]="paneRole">
<ng-template [ngTemplateOutlet]="item.contentTpl?.templateRef || null"

and maybe this reflow:

export const ngbNavFadeInTransition: NgbTransitionStartFn = (element: HTMLElement) => {
element.classList.add('active');
reflow(element);
element.classList.add('show');
};

Need to investigate further
cc @fbasso

@maxokorokov maxokorokov added this to the 8.0.1 milestone Nov 14, 2020
@maxokorokov maxokorokov modified the milestones: 8.0.1, 8.0.2 Jan 5, 2021
maxokorokov added a commit to maxokorokov/ng-bootstrap that referenced this issue Jan 11, 2021
Double reflow issue caused styles + layout calculation with tab pane hidden (without `.active`).
This caused window scroll positition adjustment as if tab pane wasn't there.

```
Before:
- reflow() in ngbRunTransition
- add('.active') in ngbNavFadeInTransition
- reflow() in ngbNavFadeInTransition
- add('.show') in ngbNavFadeInTransition

After:
- add('.active') in NgbNavOutlet
- reflow() in ngbRunTransition
- add('.show') in ngbNavFadeInTransition

```

Fixes ng-bootstrap#3900
maxokorokov added a commit to maxokorokov/ng-bootstrap that referenced this issue Jan 12, 2021
Double reflow issue caused styles + layout calculation with tab pane hidden (without `.active`).
This caused window scroll positition adjustment as if tab pane wasn't there.

```
Before:
- reflow() in ngbRunTransition
- add('.active') in ngbNavFadeInTransition
- reflow() in ngbNavFadeInTransition
- add('.show') in ngbNavFadeInTransition

After:
- add('.active') in NgbNavOutlet
- reflow() in ngbRunTransition
- add('.show') in ngbNavFadeInTransition

```

Fixes ng-bootstrap#3900
maxokorokov added a commit to maxokorokov/ng-bootstrap that referenced this issue Jan 12, 2021
Double reflow issue caused styles + layout calculation with tab pane hidden (without `.active`).
This caused window scroll positition adjustment as if tab pane wasn't there.

```
Before:
- reflow() in ngbRunTransition
- add('.active') in ngbNavFadeInTransition
- reflow() in ngbNavFadeInTransition
- add('.show') in ngbNavFadeInTransition

After:
- add('.active') in NgbNavOutlet
- reflow() in ngbRunTransition
- add('.show') in ngbNavFadeInTransition

```

Fixes ng-bootstrap#3900
maxokorokov added a commit that referenced this issue Jan 12, 2021
Double reflow issue caused styles + layout calculation with tab pane hidden (without `.active`).
This caused window scroll positition adjustment as if tab pane wasn't there.

```
Before:
- reflow() in ngbRunTransition
- add('.active') in ngbNavFadeInTransition
- reflow() in ngbNavFadeInTransition
- add('.show') in ngbNavFadeInTransition

After:
- add('.active') in NgbNavOutlet
- reflow() in ngbRunTransition
- add('.show') in ngbNavFadeInTransition

```

Fixes #3900
@jnizet
Copy link
Member Author

jnizet commented Jan 13, 2021

Thanks for the fix @maxokorokov ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants