pre-installations and preparations

This commit is contained in:
MuhammadKhalilzadeh committed 2024-05-05 11:21:00 +03:30
1 parent 3e5a0329cb
commit 201d621ac3
6977 files changed
+742826

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import { ListActionTypes, listReducer } from '../useList';
export function menuReducer(state, action) {
if (action.type === ListActionTypes.itemHover) {
return _extends({}, state, {
highlightedValue: action.item
});
}
const newState = listReducer(state, action);
// make sure an item is always highlighted
if (newState.highlightedValue === null && action.context.items.length > 0) {
return _extends({}, newState, {
highlightedValue: action.context.items[0]
});
}
if (action.type === ListActionTypes.keyDown) {
if (action.event.key === 'Escape') {
return _extends({}, newState, {
open: false
});
}
}
if (action.type === ListActionTypes.blur) {
if (!action.context.listboxRef.current?.contains(action.event.relatedTarget)) {
// To prevent the menu from closing when the focus leaves the menu to the button.
// For more details, see https://github.com/mui/material-ui/pull/36917#issuecomment-1566992698
const listboxId = action.context.listboxRef.current?.getAttribute('id');
const controlledBy = action.event.relatedTarget?.getAttribute('aria-controls');
if (listboxId && controlledBy && listboxId === controlledBy) {
return newState;
}
return _extends({}, newState, {
open: false,
highlightedValue: action.context.items[0]
});
}
}
return newState;
}