Scroll menu to checked item

This commit is contained in:
Julia Radzhabova 2019-01-28 15:53:08 +03:00
parent 327afcfaff
commit 403ffdacef

View file

@ -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];