1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | Object.defineProperty(exports, "__esModule", {
|
5 | value: true
|
6 | });
|
7 | exports.default = tabsListReducer;
|
8 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
9 | var _useList = require("../useList");
|
10 | var _useTabsList = require("./useTabsList.types");
|
11 | function 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 |