1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import { listReducer, ListActionTypes, moveHighlight } from '../useList';
|
3 | import { TabsListActionTypes } from './useTabsList.types';
|
4 | export function tabsListReducer(state, action) {
|
5 | if (action.type === TabsListActionTypes.valueChange) {
|
6 | return _extends({}, state, {
|
7 | highlightedValue: action.value
|
8 | });
|
9 | }
|
10 | const newState = listReducer(state, action);
|
11 | const {
|
12 | context: {
|
13 | selectionFollowsFocus
|
14 | }
|
15 | } = action;
|
16 | if (action.type === ListActionTypes.itemsChange) {
|
17 | if (newState.selectedValues.length > 0) {
|
18 | return _extends({}, newState, {
|
19 | highlightedValue: newState.selectedValues[0]
|
20 | });
|
21 | }
|
22 | moveHighlight(null, 'reset', action.context);
|
23 | }
|
24 | if (selectionFollowsFocus && newState.highlightedValue != null) {
|
25 | return _extends({}, newState, {
|
26 | selectedValues: [newState.highlightedValue]
|
27 | });
|
28 | }
|
29 | return newState;
|
30 | } |
\ | No newline at end of file |