angular / angular/components

Feature: Sidenav or Route Scroll Service

オープン
#4,280 コメント 15 件 リアクション 23 件 担当者 0 名 GitHub で見る
area: material/sidenav feature P2
主要言語
TypeScript
スター
25k
フォーク
6.8k
平均マージ
1日 8時間
マージ済み PR(30日)
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 を短くまとめたダイジェスト。