From 5ebab5f942bd6376477eda713942076d46bf3961 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 31 Jul 2018 15:36:30 +0300 Subject: [PATCH] chore: perfect scrollbar wrapper to maintain initial offset --- src/common-elements/perfect-scrollbar.tsx | 2 ++ src/components/SideMenu/MenuItem.tsx | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/common-elements/perfect-scrollbar.tsx b/src/common-elements/perfect-scrollbar.tsx index 40ae4dcc..da4b9cf3 100644 --- a/src/common-elements/perfect-scrollbar.tsx +++ b/src/common-elements/perfect-scrollbar.tsx @@ -27,7 +27,9 @@ export class PerfectScrollbar extends React.Component<{ private inst: PerfectScrollbarType; componentDidMount() { + const offset = (this._container.parentElement && this._container.parentElement.scrollTop) || 0; this.inst = new PerfectScrollbarConstructor(this._container, this.props.options || {}); + this._container.scrollTo(0, offset); } componentDidUpdate() { diff --git a/src/components/SideMenu/MenuItem.tsx b/src/components/SideMenu/MenuItem.tsx index caa14c28..fefc3a02 100644 --- a/src/components/SideMenu/MenuItem.tsx +++ b/src/components/SideMenu/MenuItem.tsx @@ -21,6 +21,13 @@ export class MenuItem extends React.Component { evt.stopPropagation(); }; + componentDidMount() { + const item = this.props.item; + if (item.type !== 'group' && item.active) { + this.scrollIntoView(); + } + } + componentDidUpdate() { if (this.props.item.active) { this.scrollIntoView();