浏览代码

Renamed focusFirstItem method

This renames the `focusFirstItem` method to `highlightFirstItem`, which
better reflects what is actually happening. This also ensures that the
highlight is visible when it is moved by calling
`ensureHighlightVisible`.

This closes https://github.com/select2/select2/issues/3479
This closes https://github.com/select2/select2/pull/4238
Kevin Brown 9 年之前
父节点
当前提交
9f581285d8
共有 1 个文件被更改,包括 5 次插入5 次删除
  1. 5 5
      src/js/select2/results.js

+ 5 - 5
src/js/select2/results.js

@@ -97,8 +97,7 @@ define([
     return sorter(data);
   };
 
-  Results.prototype.focusFirstItem = function () {
-
+  Results.prototype.highlightFirstItem = function () {
     var $options = this.$results
       .find('.select2-results__option[aria-selected]');
 
@@ -114,6 +113,7 @@ define([
       $options.first().trigger('mouseenter');
     }
 
+    this.ensureHighlightVisible();
   };
 
   Results.prototype.setClasses = function () {
@@ -253,7 +253,7 @@ define([
 
       if (container.isOpen()) {
         self.setClasses();
-        self.focusFirstItem();
+        self.highlightFirstItem();
       }
     });
 
@@ -276,7 +276,7 @@ define([
       }
 
       self.setClasses();
-      self.focusFirstItem();
+      self.highlightFirstItem();
     });
 
     container.on('unselect', function () {
@@ -285,7 +285,7 @@ define([
       }
 
       self.setClasses();
-      self.focusFirstItem();
+      self.highlightFirstItem();
     });
 
     container.on('open', function () {