Fix command menu selection (#10248)
- Created a state `hasUserSelectedCommandState` : This state is set to `true` when the user selects an element in the command menu list. It is set to false upon redirection or when the command menu is closed. - Modified `CommandMenuDefaultSelectionEffect` to have the expected selection behavior for the command menu
This commit is contained in:
@ -23,8 +23,9 @@ export const SelectableList = ({
|
||||
selectableItemIdArray,
|
||||
selectableItemIdMatrix,
|
||||
onEnter,
|
||||
onSelect,
|
||||
}: SelectableListProps) => {
|
||||
useSelectableListHotKeys(selectableListId, hotkeyScope);
|
||||
useSelectableListHotKeys(selectableListId, hotkeyScope, onSelect);
|
||||
|
||||
const { setSelectableItemIds, setSelectableListOnEnter, setSelectedItemId } =
|
||||
useSelectableList(selectableListId);
|
||||
|
||||
@ -11,6 +11,7 @@ type Direction = 'up' | 'down' | 'left' | 'right';
|
||||
export const useSelectableListHotKeys = (
|
||||
scopeId: string,
|
||||
hotkeyScope: string,
|
||||
onSelect?: (itemId: string) => void,
|
||||
) => {
|
||||
const findPosition = (
|
||||
selectableItemIds: string[][],
|
||||
@ -105,6 +106,7 @@ export const useSelectableListHotKeys = (
|
||||
if (isNonEmptyString(nextId)) {
|
||||
set(isSelectedItemIdSelector(nextId), true);
|
||||
set(selectedItemIdState, nextId);
|
||||
onSelect?.(nextId);
|
||||
}
|
||||
|
||||
if (isNonEmptyString(selectedItemId)) {
|
||||
@ -112,7 +114,12 @@ export const useSelectableListHotKeys = (
|
||||
}
|
||||
}
|
||||
},
|
||||
[isSelectedItemIdSelector, selectableItemIdsState, selectedItemIdState],
|
||||
[
|
||||
isSelectedItemIdSelector,
|
||||
onSelect,
|
||||
selectableItemIdsState,
|
||||
selectedItemIdState,
|
||||
],
|
||||
);
|
||||
|
||||
useScopedHotkeys(Key.ArrowUp, () => handleSelect('up'), hotkeyScope, []);
|
||||
|
||||
Reference in New Issue
Block a user