1 | import { isString } from './nodash';
|
2 | import hasOwnProperty from './hasOwnProperty';
|
3 | export function isDisabledOption(index, items) {
|
4 | var option = items[index];
|
5 | return !!option && !isString(option) && hasOwnProperty(option, 'disabled');
|
6 | }
|
7 | export function skipDisabledOptions(currentIndex, key, items) {
|
8 | var newIndex = currentIndex;
|
9 |
|
10 | while (isDisabledOption(newIndex, items)) {
|
11 | newIndex += key === 'ArrowUp' ? -1 : 1;
|
12 | }
|
13 |
|
14 | return newIndex;
|
15 | }
|
16 | export default function getUpdatedActiveIndex(currentIndex, key, items) {
|
17 | var newIndex = currentIndex;
|
18 |
|
19 | newIndex += key === 'ArrowUp' ? -1 : 1;
|
20 |
|
21 | newIndex = skipDisabledOptions(newIndex, key, items);
|
22 |
|
23 | if (newIndex === items.length) {
|
24 | newIndex = -1;
|
25 | } else if (newIndex === -2) {
|
26 | newIndex = items.length - 1;
|
27 |
|
28 | newIndex = skipDisabledOptions(newIndex, key, items);
|
29 | }
|
30 |
|
31 | return newIndex;
|
32 | } |
\ | No newline at end of file |