1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports["default"] = getUpdatedActiveIndex;
|
9 | exports.isDisabledOption = isDisabledOption;
|
10 | exports.skipDisabledOptions = skipDisabledOptions;
|
11 |
|
12 | var _nodash = require("./nodash");
|
13 |
|
14 | var _hasOwnProperty = _interopRequireDefault(require("./hasOwnProperty"));
|
15 |
|
16 | function isDisabledOption(index, items) {
|
17 | var option = items[index];
|
18 | return !!option && !(0, _nodash.isString)(option) && (0, _hasOwnProperty["default"])(option, 'disabled');
|
19 | }
|
20 |
|
21 | function skipDisabledOptions(currentIndex, key, items) {
|
22 | var newIndex = currentIndex;
|
23 |
|
24 | while (isDisabledOption(newIndex, items)) {
|
25 | newIndex += key === 'ArrowUp' ? -1 : 1;
|
26 | }
|
27 |
|
28 | return newIndex;
|
29 | }
|
30 |
|
31 | function getUpdatedActiveIndex(currentIndex, key, items) {
|
32 | var newIndex = currentIndex;
|
33 |
|
34 | newIndex += key === 'ArrowUp' ? -1 : 1;
|
35 |
|
36 | newIndex = skipDisabledOptions(newIndex, key, items);
|
37 |
|
38 | if (newIndex === items.length) {
|
39 | newIndex = -1;
|
40 | } else if (newIndex === -2) {
|
41 | newIndex = items.length - 1;
|
42 |
|
43 | newIndex = skipDisabledOptions(newIndex, key, items);
|
44 | }
|
45 |
|
46 | return newIndex;
|
47 | } |
\ | No newline at end of file |