Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix selection list scrolling after closing context menu #53120

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
QichenZhu marked this conversation as resolved.
Show resolved Hide resolved
import type useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
import type useSingleExecution from '@hooks/useSingleExecution';
import * as Browser from '@libs/Browser';
import * as SearchUIUtils from '@libs/SearchUIUtils';
import type {BaseListItemProps, BaseSelectionListProps, ListItem} from './types';
QichenZhu marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -72,11 +73,15 @@ function BaseSelectionListItemRenderer<TItem extends ListItem>({
isMultilineSupported={isMultilineSupported}
isAlternateTextMultilineSupported={isAlternateTextMultilineSupported}
alternateTextNumberOfLines={alternateTextNumberOfLines}
onFocus={() => {
onFocus={(event) => {
QichenZhu marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
if (shouldIgnoreFocus || isDisabled) {
return;
}
// Prevent unexpected scrolling on mobile Chrome after the context menu closes by ignoring programmatic focus not triggered by direct user interaction.
if (Browser.isMobileChrome() && event?.nativeEvent && !event.nativeEvent.sourceCapabilities) {
QichenZhu marked this conversation as resolved.
Show resolved Hide resolved
return;
}
setFocusedIndex(normalizedIndex);
}}
shouldSyncFocus={shouldSyncFocus}
Expand Down
4 changes: 2 additions & 2 deletions src/components/SelectionList/Search/SearchQueryListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {View} from 'react-native';
import type {ValueOf} from 'type-fest';
import Icon from '@components/Icon';
import BaseListItem from '@components/SelectionList/BaseListItem';
import type {ListItem} from '@components/SelectionList/types';
import type {ListItem, ListItemFocusEventHandler} from '@components/SelectionList/types';
import TextWithTooltip from '@components/TextWithTooltip';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand All @@ -23,7 +23,7 @@ type SearchQueryListItemProps = {
isFocused?: boolean;
showTooltip: boolean;
onSelectRow: (item: SearchQueryItem) => void;
onFocus?: () => void;
onFocus?: ListItemFocusEventHandler;
shouldSyncFocus?: boolean;
};

Expand Down
11 changes: 10 additions & 1 deletion src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
NativeSyntheticEvent,
SectionListData,
StyleProp,
TargetedEvent,
TextInput,
TextStyle,
ViewStyle,
Expand Down Expand Up @@ -84,12 +85,19 @@ type CommonListItemProps<TItem extends ListItem> = {
alternateTextNumberOfLines?: number;

/** Handles what to do when the item is focused */
onFocus?: () => void;
onFocus?: ListItemFocusEventHandler;

/** Callback to fire when the item is long pressed */
onLongPressRow?: (item: TItem) => void;
} & TRightHandSideComponent<TItem>;

type ListItemFocusEventHandler = (event: NativeSyntheticEvent<ExtendedTargetedEvent>) => void;

type ExtendedTargetedEvent = TargetedEvent & {
/** Provides information about the input device responsible for the event, or null if triggered programmatically, available in some browsers */
sourceCapabilities?: unknown;
};

type ListItem = {
/** Text to display */
text?: string;
Expand Down Expand Up @@ -653,6 +661,7 @@ export type {
InviteMemberListItemProps,
ItemLayout,
ListItem,
ListItemFocusEventHandler,
ListItemProps,
RadioListItemProps,
ReportListItemProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
Navigation.goBack(backTo);
}}
shouldShowThreeDotsButton
style={styles.headerBarDesktopHeight}
threeDotsMenuItems={threeDotsMenuItems}
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetNoCloseButton(windowWidth)}
>
Expand Down
Loading