From 403ffdacef93d18640ddb9938d66efc46ade4555 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Mon, 28 Jan 2019 15:53:08 +0300 Subject: [PATCH] Scroll menu to checked item --- apps/common/main/lib/component/Menu.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/common/main/lib/component/Menu.js b/apps/common/main/lib/component/Menu.js index fa03b2612..85a41bb78 100644 --- a/apps/common/main/lib/component/Menu.js +++ b/apps/common/main/lib/component/Menu.js @@ -424,8 +424,21 @@ define([ onAfterShowMenu: function(e) { this.trigger('show:after', this, e); - if (this.options.restoreHeight && this.scroller) - this.scroller.update({minScrollbarLength : 40}); + if (this.scroller) { + if (this.options.restoreHeight) + this.scroller.update(); + + var menuRoot = (this.cmpEl.attr('role') === 'menu') ? this.cmpEl : this.cmpEl.find('[role=menu]'), + $selected = menuRoot.find('> li .checked'); + if ($selected.length) { + var itemTop = $selected.position().top, + itemHeight = $selected.height(), + listHeight = menuRoot.height(); + if (itemTop < 0 || itemTop + itemHeight > listHeight) { + menuRoot.scrollTop(menuRoot.scrollTop() + itemTop + itemHeight - (listHeight/2)); + } + } + } if (this.$el.find('> ul > .menu-scroll').length) { var el = this.$el.find('li .checked')[0];