Fixed keyboard scrolling
Now when scrolling through results with the keyboard, the highlighted option will always be visible.
This commit is contained in:
parent
9ada3712f7
commit
9102cf9473
30
dist/css/select2.css
vendored
30
dist/css/select2.css
vendored
@ -107,22 +107,22 @@
|
|||||||
border-bottom-right-radius: 0; }
|
border-bottom-right-radius: 0; }
|
||||||
.select2-container.select2-theme-default .dropdown .search input {
|
.select2-container.select2-theme-default .dropdown .search input {
|
||||||
border: 1px solid #aaa; }
|
border: 1px solid #aaa; }
|
||||||
.select2-container.select2-theme-default .dropdown .results {
|
.select2-container.select2-theme-default .dropdown .results > .options {
|
||||||
max-height: 200px;
|
max-height: 200px;
|
||||||
overflow-y: scroll; }
|
overflow-y: auto; }
|
||||||
.select2-container.select2-theme-default .dropdown .results .options .option.group {
|
.select2-container.select2-theme-default .dropdown .results .options .option.group {
|
||||||
padding: 0; }
|
padding: 0; }
|
||||||
.select2-container.select2-theme-default .dropdown .results .options .option.group .group-label {
|
.select2-container.select2-theme-default .dropdown .results .options .option.group .group-label {
|
||||||
cursor: default;
|
cursor: default;
|
||||||
display: block;
|
display: block;
|
||||||
padding: 6px; }
|
padding: 6px; }
|
||||||
.select2-container.select2-theme-default .dropdown .results .options .option[aria-disabled=true] {
|
.select2-container.select2-theme-default .dropdown .results .options .option[aria-disabled=true] {
|
||||||
color: #666; }
|
color: #666; }
|
||||||
.select2-container.select2-theme-default .dropdown .results .options .option[aria-selected=true] {
|
.select2-container.select2-theme-default .dropdown .results .options .option[aria-selected=true] {
|
||||||
background-color: #ddd; }
|
background-color: #ddd; }
|
||||||
.select2-container.select2-theme-default .dropdown .results .options .option[aria-selected].highlighted {
|
.select2-container.select2-theme-default .dropdown .results .options .option[aria-selected].highlighted {
|
||||||
background-color: #5897fb;
|
background-color: #5897fb;
|
||||||
color: white; }
|
color: white; }
|
||||||
|
|
||||||
.s2-container {
|
.s2-container {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
2
dist/css/select2.min.css
vendored
2
dist/css/select2.min.css
vendored
File diff suppressed because one or more lines are too long
31
dist/js/select2.amd.full.js
vendored
31
dist/js/select2.amd.full.js
vendored
@ -348,6 +348,16 @@ define('select2/results',[
|
|||||||
var $next = $options.eq(nextIndex);
|
var $next = $options.eq(nextIndex);
|
||||||
|
|
||||||
$next.trigger('mouseenter');
|
$next.trigger('mouseenter');
|
||||||
|
|
||||||
|
var currentOffset = self.$results.offset().top;
|
||||||
|
var nextTop = $next.offset().top;
|
||||||
|
var nextOffset = self.$results.scrollTop() + (nextTop - currentOffset);
|
||||||
|
|
||||||
|
if (nextIndex === 0) {
|
||||||
|
self.$results.scrollTop(0);
|
||||||
|
} else if (nextTop - currentOffset < 0) {
|
||||||
|
self.$results.scrollTop(nextOffset);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
container.on('results:next', function () {
|
container.on('results:next', function () {
|
||||||
@ -367,8 +377,17 @@ define('select2/results',[
|
|||||||
var $next = $options.eq(nextIndex);
|
var $next = $options.eq(nextIndex);
|
||||||
|
|
||||||
$next.trigger('mouseenter');
|
$next.trigger('mouseenter');
|
||||||
console.log($next.offset().top, self.$results.parent().scrollTop());
|
|
||||||
//self.$results.parents().scrollTop($next.offset().top);
|
var currentOffset = self.$results.offset().top +
|
||||||
|
self.$results.outerHeight(false);
|
||||||
|
var nextBottom = $next.offset().top + $next.outerHeight(false);
|
||||||
|
var nextOffset = self.$results.scrollTop() + nextBottom - currentOffset;
|
||||||
|
|
||||||
|
if (nextIndex === 0) {
|
||||||
|
self.$results.scrollTop(0);
|
||||||
|
} else if (nextBottom > currentOffset) {
|
||||||
|
self.$results.scrollTop(nextOffset);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$results.on('mouseup', '.option[aria-selected]', function (evt) {
|
this.$results.on('mouseup', '.option[aria-selected]', function (evt) {
|
||||||
@ -545,7 +564,7 @@ define('select2/selection/single',[
|
|||||||
// User exits the container
|
// User exits the container
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$selection.on('keyup', function (evt) {
|
this.$selection.on('keydown', function (evt) {
|
||||||
var key = evt.which;
|
var key = evt.which;
|
||||||
|
|
||||||
if (container.isOpen()) {
|
if (container.isOpen()) {
|
||||||
@ -553,8 +572,12 @@ define('select2/selection/single',[
|
|||||||
self.trigger('results:select');
|
self.trigger('results:select');
|
||||||
} else if (key == KEYS.UP) {
|
} else if (key == KEYS.UP) {
|
||||||
self.trigger('results:previous');
|
self.trigger('results:previous');
|
||||||
|
|
||||||
|
evt.preventDefault();
|
||||||
} else if (key == KEYS.DOWN) {
|
} else if (key == KEYS.DOWN) {
|
||||||
self.trigger('results:next');
|
self.trigger('results:next');
|
||||||
|
|
||||||
|
evt.preventDefault();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (key == KEYS.ENTER || key == KEYS.SPACE) {
|
if (key == KEYS.ENTER || key == KEYS.SPACE) {
|
||||||
@ -759,7 +782,7 @@ define('select2/data/base',[
|
|||||||
};
|
};
|
||||||
|
|
||||||
BaseAdapter.prototype.generateResultId = function (data) {
|
BaseAdapter.prototype.generateResultId = function (data) {
|
||||||
var id = '';
|
var id = 'select2-result-';
|
||||||
|
|
||||||
for (var i = 0; i < 4; i++) {
|
for (var i = 0; i < 4; i++) {
|
||||||
var r = Math.floor(Math.random() * 16);
|
var r = Math.floor(Math.random() * 16);
|
||||||
|
31
dist/js/select2.amd.js
vendored
31
dist/js/select2.amd.js
vendored
@ -348,6 +348,16 @@ define('select2/results',[
|
|||||||
var $next = $options.eq(nextIndex);
|
var $next = $options.eq(nextIndex);
|
||||||
|
|
||||||
$next.trigger('mouseenter');
|
$next.trigger('mouseenter');
|
||||||
|
|
||||||
|
var currentOffset = self.$results.offset().top;
|
||||||
|
var nextTop = $next.offset().top;
|
||||||
|
var nextOffset = self.$results.scrollTop() + (nextTop - currentOffset);
|
||||||
|
|
||||||
|
if (nextIndex === 0) {
|
||||||
|
self.$results.scrollTop(0);
|
||||||
|
} else if (nextTop - currentOffset < 0) {
|
||||||
|
self.$results.scrollTop(nextOffset);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
container.on('results:next', function () {
|
container.on('results:next', function () {
|
||||||
@ -367,8 +377,17 @@ define('select2/results',[
|
|||||||
var $next = $options.eq(nextIndex);
|
var $next = $options.eq(nextIndex);
|
||||||
|
|
||||||
$next.trigger('mouseenter');
|
$next.trigger('mouseenter');
|
||||||
console.log($next.offset().top, self.$results.parent().scrollTop());
|
|
||||||
//self.$results.parents().scrollTop($next.offset().top);
|
var currentOffset = self.$results.offset().top +
|
||||||
|
self.$results.outerHeight(false);
|
||||||
|
var nextBottom = $next.offset().top + $next.outerHeight(false);
|
||||||
|
var nextOffset = self.$results.scrollTop() + nextBottom - currentOffset;
|
||||||
|
|
||||||
|
if (nextIndex === 0) {
|
||||||
|
self.$results.scrollTop(0);
|
||||||
|
} else if (nextBottom > currentOffset) {
|
||||||
|
self.$results.scrollTop(nextOffset);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$results.on('mouseup', '.option[aria-selected]', function (evt) {
|
this.$results.on('mouseup', '.option[aria-selected]', function (evt) {
|
||||||
@ -545,7 +564,7 @@ define('select2/selection/single',[
|
|||||||
// User exits the container
|
// User exits the container
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$selection.on('keyup', function (evt) {
|
this.$selection.on('keydown', function (evt) {
|
||||||
var key = evt.which;
|
var key = evt.which;
|
||||||
|
|
||||||
if (container.isOpen()) {
|
if (container.isOpen()) {
|
||||||
@ -553,8 +572,12 @@ define('select2/selection/single',[
|
|||||||
self.trigger('results:select');
|
self.trigger('results:select');
|
||||||
} else if (key == KEYS.UP) {
|
} else if (key == KEYS.UP) {
|
||||||
self.trigger('results:previous');
|
self.trigger('results:previous');
|
||||||
|
|
||||||
|
evt.preventDefault();
|
||||||
} else if (key == KEYS.DOWN) {
|
} else if (key == KEYS.DOWN) {
|
||||||
self.trigger('results:next');
|
self.trigger('results:next');
|
||||||
|
|
||||||
|
evt.preventDefault();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (key == KEYS.ENTER || key == KEYS.SPACE) {
|
if (key == KEYS.ENTER || key == KEYS.SPACE) {
|
||||||
@ -759,7 +782,7 @@ define('select2/data/base',[
|
|||||||
};
|
};
|
||||||
|
|
||||||
BaseAdapter.prototype.generateResultId = function (data) {
|
BaseAdapter.prototype.generateResultId = function (data) {
|
||||||
var id = '';
|
var id = 'select2-result-';
|
||||||
|
|
||||||
for (var i = 0; i < 4; i++) {
|
for (var i = 0; i < 4; i++) {
|
||||||
var r = Math.floor(Math.random() * 16);
|
var r = Math.floor(Math.random() * 16);
|
||||||
|
31
dist/js/select2.full.js
vendored
31
dist/js/select2.full.js
vendored
@ -9886,6 +9886,16 @@ define('select2/results',[
|
|||||||
var $next = $options.eq(nextIndex);
|
var $next = $options.eq(nextIndex);
|
||||||
|
|
||||||
$next.trigger('mouseenter');
|
$next.trigger('mouseenter');
|
||||||
|
|
||||||
|
var currentOffset = self.$results.offset().top;
|
||||||
|
var nextTop = $next.offset().top;
|
||||||
|
var nextOffset = self.$results.scrollTop() + (nextTop - currentOffset);
|
||||||
|
|
||||||
|
if (nextIndex === 0) {
|
||||||
|
self.$results.scrollTop(0);
|
||||||
|
} else if (nextTop - currentOffset < 0) {
|
||||||
|
self.$results.scrollTop(nextOffset);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
container.on('results:next', function () {
|
container.on('results:next', function () {
|
||||||
@ -9905,8 +9915,17 @@ define('select2/results',[
|
|||||||
var $next = $options.eq(nextIndex);
|
var $next = $options.eq(nextIndex);
|
||||||
|
|
||||||
$next.trigger('mouseenter');
|
$next.trigger('mouseenter');
|
||||||
console.log($next.offset().top, self.$results.parent().scrollTop());
|
|
||||||
//self.$results.parents().scrollTop($next.offset().top);
|
var currentOffset = self.$results.offset().top +
|
||||||
|
self.$results.outerHeight(false);
|
||||||
|
var nextBottom = $next.offset().top + $next.outerHeight(false);
|
||||||
|
var nextOffset = self.$results.scrollTop() + nextBottom - currentOffset;
|
||||||
|
|
||||||
|
if (nextIndex === 0) {
|
||||||
|
self.$results.scrollTop(0);
|
||||||
|
} else if (nextBottom > currentOffset) {
|
||||||
|
self.$results.scrollTop(nextOffset);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$results.on('mouseup', '.option[aria-selected]', function (evt) {
|
this.$results.on('mouseup', '.option[aria-selected]', function (evt) {
|
||||||
@ -10083,7 +10102,7 @@ define('select2/selection/single',[
|
|||||||
// User exits the container
|
// User exits the container
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$selection.on('keyup', function (evt) {
|
this.$selection.on('keydown', function (evt) {
|
||||||
var key = evt.which;
|
var key = evt.which;
|
||||||
|
|
||||||
if (container.isOpen()) {
|
if (container.isOpen()) {
|
||||||
@ -10091,8 +10110,12 @@ define('select2/selection/single',[
|
|||||||
self.trigger('results:select');
|
self.trigger('results:select');
|
||||||
} else if (key == KEYS.UP) {
|
} else if (key == KEYS.UP) {
|
||||||
self.trigger('results:previous');
|
self.trigger('results:previous');
|
||||||
|
|
||||||
|
evt.preventDefault();
|
||||||
} else if (key == KEYS.DOWN) {
|
} else if (key == KEYS.DOWN) {
|
||||||
self.trigger('results:next');
|
self.trigger('results:next');
|
||||||
|
|
||||||
|
evt.preventDefault();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (key == KEYS.ENTER || key == KEYS.SPACE) {
|
if (key == KEYS.ENTER || key == KEYS.SPACE) {
|
||||||
@ -10297,7 +10320,7 @@ define('select2/data/base',[
|
|||||||
};
|
};
|
||||||
|
|
||||||
BaseAdapter.prototype.generateResultId = function (data) {
|
BaseAdapter.prototype.generateResultId = function (data) {
|
||||||
var id = '';
|
var id = 'select2-result-';
|
||||||
|
|
||||||
for (var i = 0; i < 4; i++) {
|
for (var i = 0; i < 4; i++) {
|
||||||
var r = Math.floor(Math.random() * 16);
|
var r = Math.floor(Math.random() * 16);
|
||||||
|
4
dist/js/select2.full.min.js
vendored
4
dist/js/select2.full.min.js
vendored
File diff suppressed because one or more lines are too long
31
dist/js/select2.js
vendored
31
dist/js/select2.js
vendored
@ -777,6 +777,16 @@ define('select2/results',[
|
|||||||
var $next = $options.eq(nextIndex);
|
var $next = $options.eq(nextIndex);
|
||||||
|
|
||||||
$next.trigger('mouseenter');
|
$next.trigger('mouseenter');
|
||||||
|
|
||||||
|
var currentOffset = self.$results.offset().top;
|
||||||
|
var nextTop = $next.offset().top;
|
||||||
|
var nextOffset = self.$results.scrollTop() + (nextTop - currentOffset);
|
||||||
|
|
||||||
|
if (nextIndex === 0) {
|
||||||
|
self.$results.scrollTop(0);
|
||||||
|
} else if (nextTop - currentOffset < 0) {
|
||||||
|
self.$results.scrollTop(nextOffset);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
container.on('results:next', function () {
|
container.on('results:next', function () {
|
||||||
@ -796,8 +806,17 @@ define('select2/results',[
|
|||||||
var $next = $options.eq(nextIndex);
|
var $next = $options.eq(nextIndex);
|
||||||
|
|
||||||
$next.trigger('mouseenter');
|
$next.trigger('mouseenter');
|
||||||
console.log($next.offset().top, self.$results.parent().scrollTop());
|
|
||||||
//self.$results.parents().scrollTop($next.offset().top);
|
var currentOffset = self.$results.offset().top +
|
||||||
|
self.$results.outerHeight(false);
|
||||||
|
var nextBottom = $next.offset().top + $next.outerHeight(false);
|
||||||
|
var nextOffset = self.$results.scrollTop() + nextBottom - currentOffset;
|
||||||
|
|
||||||
|
if (nextIndex === 0) {
|
||||||
|
self.$results.scrollTop(0);
|
||||||
|
} else if (nextBottom > currentOffset) {
|
||||||
|
self.$results.scrollTop(nextOffset);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$results.on('mouseup', '.option[aria-selected]', function (evt) {
|
this.$results.on('mouseup', '.option[aria-selected]', function (evt) {
|
||||||
@ -974,7 +993,7 @@ define('select2/selection/single',[
|
|||||||
// User exits the container
|
// User exits the container
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$selection.on('keyup', function (evt) {
|
this.$selection.on('keydown', function (evt) {
|
||||||
var key = evt.which;
|
var key = evt.which;
|
||||||
|
|
||||||
if (container.isOpen()) {
|
if (container.isOpen()) {
|
||||||
@ -982,8 +1001,12 @@ define('select2/selection/single',[
|
|||||||
self.trigger('results:select');
|
self.trigger('results:select');
|
||||||
} else if (key == KEYS.UP) {
|
} else if (key == KEYS.UP) {
|
||||||
self.trigger('results:previous');
|
self.trigger('results:previous');
|
||||||
|
|
||||||
|
evt.preventDefault();
|
||||||
} else if (key == KEYS.DOWN) {
|
} else if (key == KEYS.DOWN) {
|
||||||
self.trigger('results:next');
|
self.trigger('results:next');
|
||||||
|
|
||||||
|
evt.preventDefault();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (key == KEYS.ENTER || key == KEYS.SPACE) {
|
if (key == KEYS.ENTER || key == KEYS.SPACE) {
|
||||||
@ -1188,7 +1211,7 @@ define('select2/data/base',[
|
|||||||
};
|
};
|
||||||
|
|
||||||
BaseAdapter.prototype.generateResultId = function (data) {
|
BaseAdapter.prototype.generateResultId = function (data) {
|
||||||
var id = '';
|
var id = 'select2-result-';
|
||||||
|
|
||||||
for (var i = 0; i < 4; i++) {
|
for (var i = 0; i < 4; i++) {
|
||||||
var r = Math.floor(Math.random() * 16);
|
var r = Math.floor(Math.random() * 16);
|
||||||
|
2
dist/js/select2.min.js
vendored
2
dist/js/select2.min.js
vendored
File diff suppressed because one or more lines are too long
2
src/js/select2/data/base.js
vendored
2
src/js/select2/data/base.js
vendored
@ -20,7 +20,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
BaseAdapter.prototype.generateResultId = function (data) {
|
BaseAdapter.prototype.generateResultId = function (data) {
|
||||||
var id = '';
|
var id = 'select2-result-';
|
||||||
|
|
||||||
for (var i = 0; i < 4; i++) {
|
for (var i = 0; i < 4; i++) {
|
||||||
var r = Math.floor(Math.random() * 16);
|
var r = Math.floor(Math.random() * 16);
|
||||||
|
23
src/js/select2/results.js
vendored
23
src/js/select2/results.js
vendored
@ -209,6 +209,16 @@ define([
|
|||||||
var $next = $options.eq(nextIndex);
|
var $next = $options.eq(nextIndex);
|
||||||
|
|
||||||
$next.trigger('mouseenter');
|
$next.trigger('mouseenter');
|
||||||
|
|
||||||
|
var currentOffset = self.$results.offset().top;
|
||||||
|
var nextTop = $next.offset().top;
|
||||||
|
var nextOffset = self.$results.scrollTop() + (nextTop - currentOffset);
|
||||||
|
|
||||||
|
if (nextIndex === 0) {
|
||||||
|
self.$results.scrollTop(0);
|
||||||
|
} else if (nextTop - currentOffset < 0) {
|
||||||
|
self.$results.scrollTop(nextOffset);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
container.on('results:next', function () {
|
container.on('results:next', function () {
|
||||||
@ -228,8 +238,17 @@ define([
|
|||||||
var $next = $options.eq(nextIndex);
|
var $next = $options.eq(nextIndex);
|
||||||
|
|
||||||
$next.trigger('mouseenter');
|
$next.trigger('mouseenter');
|
||||||
console.log($next.offset().top, self.$results.parent().scrollTop());
|
|
||||||
//self.$results.parents().scrollTop($next.offset().top);
|
var currentOffset = self.$results.offset().top +
|
||||||
|
self.$results.outerHeight(false);
|
||||||
|
var nextBottom = $next.offset().top + $next.outerHeight(false);
|
||||||
|
var nextOffset = self.$results.scrollTop() + nextBottom - currentOffset;
|
||||||
|
|
||||||
|
if (nextIndex === 0) {
|
||||||
|
self.$results.scrollTop(0);
|
||||||
|
} else if (nextBottom > currentOffset) {
|
||||||
|
self.$results.scrollTop(nextOffset);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$results.on('mouseup', '.option[aria-selected]', function (evt) {
|
this.$results.on('mouseup', '.option[aria-selected]', function (evt) {
|
||||||
|
6
src/js/select2/selection/single.js
vendored
6
src/js/select2/selection/single.js
vendored
@ -68,7 +68,7 @@ define([
|
|||||||
// User exits the container
|
// User exits the container
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$selection.on('keyup', function (evt) {
|
this.$selection.on('keydown', function (evt) {
|
||||||
var key = evt.which;
|
var key = evt.which;
|
||||||
|
|
||||||
if (container.isOpen()) {
|
if (container.isOpen()) {
|
||||||
@ -76,8 +76,12 @@ define([
|
|||||||
self.trigger('results:select');
|
self.trigger('results:select');
|
||||||
} else if (key == KEYS.UP) {
|
} else if (key == KEYS.UP) {
|
||||||
self.trigger('results:previous');
|
self.trigger('results:previous');
|
||||||
|
|
||||||
|
evt.preventDefault();
|
||||||
} else if (key == KEYS.DOWN) {
|
} else if (key == KEYS.DOWN) {
|
||||||
self.trigger('results:next');
|
self.trigger('results:next');
|
||||||
|
|
||||||
|
evt.preventDefault();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (key == KEYS.ENTER || key == KEYS.SPACE) {
|
if (key == KEYS.ENTER || key == KEYS.SPACE) {
|
||||||
|
@ -78,8 +78,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.results {
|
.results {
|
||||||
max-height: 200px;
|
&> .options {
|
||||||
overflow-y: scroll;
|
max-height: 200px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.options {
|
.options {
|
||||||
.option {
|
.option {
|
||||||
|
Loading…
Reference in New Issue
Block a user