1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import { ListActionTypes, listReducer } from '../useList';
|
3 | export default function menuReducer(state, action) {
|
4 | if (action.type === ListActionTypes.itemHover) {
|
5 | return state;
|
6 | }
|
7 | const newState = listReducer(state, action);
|
8 |
|
9 |
|
10 | if (newState.highlightedValue === null && action.context.items.length > 0) {
|
11 | return _extends({}, newState, {
|
12 | highlightedValue: action.context.items[0]
|
13 | });
|
14 | }
|
15 | if (action.type === ListActionTypes.keyDown) {
|
16 | if (action.event.key === 'Escape') {
|
17 | return _extends({}, newState, {
|
18 | open: false
|
19 | });
|
20 | }
|
21 | }
|
22 | if (action.type === ListActionTypes.blur) {
|
23 | if (!action.context.listboxRef.current?.contains(action.event.relatedTarget)) {
|
24 | return _extends({}, newState, {
|
25 | open: false,
|
26 | highlightedValue: action.context.items[0]
|
27 | });
|
28 | }
|
29 | }
|
30 | return newState;
|
31 | } |
\ | No newline at end of file |