mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
28 lines
542 B
JavaScript
28 lines
542 B
JavaScript
import {J, K, UP, DOWN} from '../../key/key.js';
|
|
|
|
export default (el, {keyCode}) => {
|
|
if (keyCode === DOWN || keyCode === J)
|
|
return down(el);
|
|
|
|
if (keyCode === UP || keyCode === K)
|
|
return up(el);
|
|
};
|
|
|
|
function down(el) {
|
|
const {length} = el;
|
|
|
|
if (el.selectedIndex === length - 1)
|
|
el.selectedIndex = 0;
|
|
else
|
|
++el.selectedIndex;
|
|
}
|
|
|
|
function up(el) {
|
|
const {length} = el;
|
|
|
|
if (!el.selectedIndex)
|
|
el.selectedIndex = length - 1;
|
|
else
|
|
--el.selectedIndex;
|
|
}
|
|
|