components icon indicating copy to clipboard operation
components copied to clipboard

ScrollTop is not working when tab is changed from left to right in MdTabGroup

Open ubarsaiyan opened this issue 9 years ago • 2 comments

Bug: I wrote a code that saves the scroll position of the current tab body's div and when we return to that tab it sets the scroll position to the stored value. By logging in the console I find the values stored and retrieved to be correct. But: When I select a tab that is to the right of the currently active tab, the scroll position can not be set. But the same code sets the scroll position of the div if I select a tab that is towards the left of the currently active tab.

Excerpts from the code: tab.service.ts:

public scrollTab() { let el = document.getElementById('items-container'); this.tabs[this.currentTab].scrollPosition = el.scrollTop; console.log(this.tabs[this.currentTab].scrollPosition + ' during Change'); }

public setScroll() { const el = document.getElementById('items-container'); if (el.scrollTop !== undefined) { console.log(this.tabs[this.currentTab].scrollPosition + ' during Set'); el.scrollTop = this.tabs[this.currentTab].scrollPosition; } } public switchTab(index: number) { this.currentTab = index; this.location.go('/' + this.tabs[index].path); this.displayEditor.next(false); }

tabs.component.html:

<md-tab-group class="tabbar" (focusChange)="tabService.scrollTab()" (selectChange)="tabService.switchTab($event.index); tabService.setScroll()" [selectedIndex]="tabService.currentTab" #tabgroup>

ubarsaiyan avatar Jun 06 '17 19:06 ubarsaiyan

For any help using Material or Angular, please refer to our great community, such as Gitter or StackOverflow. If you find an issue with Material, please feel free to open an issue but please follow the issue template which help us reproduce and resolve with a fix.

andrewseguin avatar Jun 06 '17 22:06 andrewseguin

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.