UNPKG

1.21 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4Object.defineProperty(exports, "__esModule", {
5 value: true
6});
7exports.default = tabsListReducer;
8var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9var _useList = require("../useList");
10var _useTabsList = require("./useTabsList.types");
11function tabsListReducer(state, action) {
12 if (action.type === _useTabsList.TabsListActionTypes.valueChange) {
13 return (0, _extends2.default)({}, state, {
14 highlightedValue: action.value
15 });
16 }
17 const newState = (0, _useList.listReducer)(state, action);
18 const {
19 context: {
20 selectionFollowsFocus
21 }
22 } = action;
23 if (action.type === _useList.ListActionTypes.itemsChange) {
24 if (newState.selectedValues.length > 0) {
25 return (0, _extends2.default)({}, newState, {
26 highlightedValue: newState.selectedValues[0]
27 });
28 }
29 (0, _useList.moveHighlight)(null, 'reset', action.context);
30 }
31 if (selectionFollowsFocus && newState.highlightedValue != null) {
32 return (0, _extends2.default)({}, newState, {
33 selectedValues: [newState.highlightedValue]
34 });
35 }
36 return newState;
37}
\No newline at end of file