Skip to content

Commit 7b2d051

Browse files
authored
Merge pull request #818 from psyafter/patch-2
Auto scroll to first selected item in single mode
2 parents 0b869a5 + 93c18c5 commit 7b2d051

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/jquery.multiselect.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,12 +763,18 @@
763763
this.position();
764764

765765

766-
// select the first not disabled option or the filter input if available
766+
// Set focus to the first selected (in single mode) or not disabled option or the filter input if available
767+
var $firstSelected = !o.multiple ? $container.find('li>.ui-state-active').first() : [];
768+
if ($firstSelected.length) {
769+
$firstSelected.trigger('mouseover').trigger('mouseenter').find('input').trigger('focus');
770+
}
767771
var filter = this.header.find(".ui-multiselect-filter");
768772
if(filter.length) {
769773
filter.first().find('input').trigger('focus');
770774
} else if(this.labels.length){
771-
this.labels.filter(':not(.ui-state-disabled)').eq(0).trigger('mouseover').trigger('mouseenter').find('input').trigger('focus');
775+
if (!$firstSelected.length) {
776+
this.labels.filter(':not(.ui-state-disabled)').eq(0).trigger('mouseover').trigger('mouseenter').find('input').trigger('focus');
777+
}
772778
} else {
773779
this.header.find('a').first().trigger('focus');
774780
}

0 commit comments

Comments
 (0)