angular / angular/components

Feature: Sidenav or Route Scroll Service

未关闭
#4,280 15 条评论 23 个 reaction 已指派 0 人 在 GitHub 查看
area: material/sidenav feature P2
主要语言
TypeScript
星标
25k
派生
6.8k
平均合并
1 天 8 小时
30 天内合并 PR
91

描述

#### Bug, feature request, or proposal:
Feature Request

#### What is the expected behavior?
Using a common native API call to `window.scrollTo(0, 0)` or doing something similar on the document body, etc would allow for scrolling the page to the top after a route ends when using a `sidenav`, otherwise the next view starts at the same position in the page.

#### What is the current behavior?
Routing between views within the sidenav content maintains the same scroll position assuming the content is the same length.

#### What are the steps to reproduce?
Add a sidenav and try to scroll to the top of the page anywhere at anytime. Eventually, I figure out this solution and stuck it in my `app.component`.

```
this.router.events
.filter(event => event instanceof NavigationEnd)
.subscribe(() => {
const contentContainer = document.querySelector('.mat-sidenav-content');
if (contentContainer) {
document.querySelector('.mat-sidenav-content').scroll({ top: 0, left: 0, behavior: 'smooth' });
} else {
this.window.scroll({ top: 0, left: 0, behavior: 'smooth' });
}
});
```

#### What is the use-case or motivation for changing an existing behavior?
Routing between views within the sidenav should be able to start at the top of the page, which is a common use case. Also, scrolling a browser using the native API has been around forever so it's a bit confusing when you expect it or one of the many variations of scrolling to work and they don't.

#### Which versions of Angular, Material, OS, browsers are affected?
Angular 4.0.2
Angular Material 2.0.0-beta.3

贡献指南

打开贡献指南

调研方向

从 issue 中展示的 app.component workaround 开始,尤其关注 router.events 和 NavigationEnd,并检查 .mat-sidenav-content 如何负责滚动。确定路由变更的适当入口点,并验证在 sidenav 视图之间导航时,内容的滚动位置会重置到顶部,而不包含 sidenav 内容。没有指定具体的测试文件,因此请为路由导航和滚动行为添加或找到覆盖测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
frontend, web-dev
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。