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,
|
items: filteredUsers,
|
||||||
onSelect: handleSelectMention,
|
onSelect: handleSelectMention,
|
||||||
shouldSelectOnTab: true,
|
shouldSelectOnTab: true,
|
||||||
|
shouldSaveSelectionOnUpdateItems: true,
|
||||||
onClose,
|
onClose,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import cycleRestrict from '../../../../util/cycleRestrict';
|
|||||||
export function useKeyboardNavigation({
|
export function useKeyboardNavigation({
|
||||||
isActive,
|
isActive,
|
||||||
isHorizontal,
|
isHorizontal,
|
||||||
|
shouldSaveSelectionOnUpdateItems,
|
||||||
shouldRemoveSelectionOnReset,
|
shouldRemoveSelectionOnReset,
|
||||||
noArrowNavigation,
|
noArrowNavigation,
|
||||||
items,
|
items,
|
||||||
@ -14,6 +15,7 @@ export function useKeyboardNavigation({
|
|||||||
}: {
|
}: {
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
isHorizontal?: boolean;
|
isHorizontal?: boolean;
|
||||||
|
shouldSaveSelectionOnUpdateItems?: boolean;
|
||||||
shouldRemoveSelectionOnReset?: boolean;
|
shouldRemoveSelectionOnReset?: boolean;
|
||||||
noArrowNavigation?: boolean;
|
noArrowNavigation?: boolean;
|
||||||
items?: any[];
|
items?: any[];
|
||||||
@ -46,9 +48,12 @@ export function useKeyboardNavigation({
|
|||||||
}
|
}
|
||||||
}, [items, onSelect, selectedItemIndex]);
|
}, [items, onSelect, selectedItemIndex]);
|
||||||
|
|
||||||
|
const isSelectionOutOfRange = !items || selectedItemIndex > items.length - 1;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!shouldSaveSelectionOnUpdateItems || isSelectionOutOfRange) {
|
||||||
setSelectedItemIndex(shouldRemoveSelectionOnReset ? -1 : 0);
|
setSelectedItemIndex(shouldRemoveSelectionOnReset ? -1 : 0);
|
||||||
}, [items, shouldRemoveSelectionOnReset]);
|
}
|
||||||
|
}, [isSelectionOutOfRange, shouldRemoveSelectionOnReset, shouldSaveSelectionOnUpdateItems]);
|
||||||
|
|
||||||
useEffect(() => (isActive ? captureKeyboardListeners({
|
useEffect(() => (isActive ? captureKeyboardListeners({
|
||||||
onEsc: onClose,
|
onEsc: onClose,
|
||||||
|
Loading…
Reference in New Issue
Block a user