mirror of
https://github.com/danog/telegram-tt.git
synced 2024-12-13 17:47:39 +01:00
Mention Tooltip: Fix resetting active item (#1509)
This commit is contained in:
parent
b798d92f07
commit
05a5ce0e17
@ -52,6 +52,7 @@ const MentionTooltip: FC<OwnProps> = ({
|
||||
items: filteredUsers,
|
||||
onSelect: handleSelectMention,
|
||||
shouldSelectOnTab: true,
|
||||
shouldSaveSelectionOnUpdateItems: true,
|
||||
onClose,
|
||||
});
|
||||
|
||||
|
@ -5,6 +5,7 @@ import cycleRestrict from '../../../../util/cycleRestrict';
|
||||
export function useKeyboardNavigation({
|
||||
isActive,
|
||||
isHorizontal,
|
||||
shouldSaveSelectionOnUpdateItems,
|
||||
shouldRemoveSelectionOnReset,
|
||||
noArrowNavigation,
|
||||
items,
|
||||
@ -14,6 +15,7 @@ export function useKeyboardNavigation({
|
||||
}: {
|
||||
isActive: boolean;
|
||||
isHorizontal?: boolean;
|
||||
shouldSaveSelectionOnUpdateItems?: boolean;
|
||||
shouldRemoveSelectionOnReset?: boolean;
|
||||
noArrowNavigation?: boolean;
|
||||
items?: any[];
|
||||
@ -46,9 +48,12 @@ export function useKeyboardNavigation({
|
||||
}
|
||||
}, [items, onSelect, selectedItemIndex]);
|
||||
|
||||
const isSelectionOutOfRange = !items || selectedItemIndex > items.length - 1;
|
||||
useEffect(() => {
|
||||
if (!shouldSaveSelectionOnUpdateItems || isSelectionOutOfRange) {
|
||||
setSelectedItemIndex(shouldRemoveSelectionOnReset ? -1 : 0);
|
||||
}, [items, shouldRemoveSelectionOnReset]);
|
||||
}
|
||||
}, [isSelectionOutOfRange, shouldRemoveSelectionOnReset, shouldSaveSelectionOnUpdateItems]);
|
||||
|
||||
useEffect(() => (isActive ? captureKeyboardListeners({
|
||||
onEsc: onClose,
|
||||
|
Loading…
Reference in New Issue
Block a user