From d214a5219207911bcf4987de985b2b611d5b6883 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Fri, 4 Nov 2016 11:26:29 -0700 Subject: [PATCH] fix(prefs): Only scroll to top when switching tabs --- internal_packages/preferences/lib/preferences-root.jsx | 10 ++++++---- .../preferences/lib/tabs/preferences-accounts.jsx | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/internal_packages/preferences/lib/preferences-root.jsx b/internal_packages/preferences/lib/preferences-root.jsx index 342428406..a52419291 100644 --- a/internal_packages/preferences/lib/preferences-root.jsx +++ b/internal_packages/preferences/lib/preferences-root.jsx @@ -28,10 +28,12 @@ class PreferencesRoot extends React.Component { this._focusContent(); } - componentDidUpdate() { - const scrollRegion = document.querySelector(".preferences-content .scroll-region-content"); - scrollRegion.scrollTop = 0; - this._focusContent(); + componentDidUpdate(oldProps) { + if (oldProps.tab !== this.props.tab) { + const scrollRegion = document.querySelector(".preferences-content .scroll-region-content"); + scrollRegion.scrollTop = 0; + this._focusContent(); + } } _localHandlers() { diff --git a/internal_packages/preferences/lib/tabs/preferences-accounts.jsx b/internal_packages/preferences/lib/tabs/preferences-accounts.jsx index 407f0d240..07f65211d 100644 --- a/internal_packages/preferences/lib/tabs/preferences-accounts.jsx +++ b/internal_packages/preferences/lib/tabs/preferences-accounts.jsx @@ -19,7 +19,9 @@ class PreferencesAccounts extends React.Component { } componentWillUnmount() { - this.unsubscribe(); + if (this.unsubscribe) { + this.unsubscribe(); + } } getStateFromStores({selected} = {}) {