Fix keyboard issues with the custom dropdown

pull/1/head
yflory 4 years ago
parent 869d3d4255
commit 3278598487

@ -2254,7 +2254,12 @@ define([
}); });
$container.keydown(function (e) { $container.keydown(function (e) {
var $value = $innerblock.find('[data-value].cp-dropdown-element-active:visible'); var $value = $innerblock.find('[data-value].cp-dropdown-element-active:visible');
if (!$value.length) {
$value = $innerblock.find('[data-value]').first();
}
if (e.which === 38) { // Up if (e.which === 38) { // Up
e.preventDefault();
e.stopPropagation();
if ($value.length) { if ($value.length) {
$value.mouseleave(); $value.mouseleave();
var $prev = $value.prev(); var $prev = $value.prev();
@ -2263,6 +2268,8 @@ define([
} }
} }
if (e.which === 40) { // Down if (e.which === 40) { // Down
e.preventDefault();
e.stopPropagation();
if ($value.length) { if ($value.length) {
$value.mouseleave(); $value.mouseleave();
var $next = $value.next(); var $next = $value.next();
@ -2271,12 +2278,16 @@ define([
} }
} }
if (e.which === 13) { //Enter if (e.which === 13) { //Enter
e.preventDefault();
e.stopPropagation();
if ($value.length) { if ($value.length) {
$value.click(); $value.click();
hide(); hide();
} }
} }
if (e.which === 27) { // Esc if (e.which === 27) { // Esc
e.preventDefault();
e.stopPropagation();
$value.mouseleave(); $value.mouseleave();
hide(); hide();
} }

Loading…
Cancel
Save