Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b348ff6
Fix Copilot account switcher keyboard interactions
emkhalid Sep 30, 2026
0cac53b
Merge branch 'main' into fix/96225-account-switcher-keyboard-navigation
emkhalid Sep 30, 2026
b5a4318
Merge branch 'main' into fix/96225-account-switcher-keyboard-navigation
emkhalid Oct 12, 2026
b424943
Merge branch 'main' into fix/96225-account-switcher-keyboard-navigation
emkhalid Oct 16, 2026
9511ae3
Merge branch 'main' into fix/96225-account-switcher-keyboard-navigation
emkhalid Oct 17, 2026
05493c1
Fix Enter handling for focused account switcher controls
emkhalid Oct 17, 2026
18264ab
Announce arrow-focused accounts to VoiceOver
emkhalid Oct 17, 2026
072315a
Merge branch 'main' into fix/96225-account-switcher-keyboard-navigation
emkhalid Oct 28, 2026
487d430
Merge branch 'main' into fix/96225-account-switcher-keyboard-navigation
emkhalid Oct 30, 2026
0268965
Merge branch 'main' into fix/96225-account-switcher-keyboard-navigation
emkhalid Nov 1, 2026
65498f3
tab enter account switch with two accounts fixed
emkhalid Nov 1, 2026
808aa37
Fix account switcher keyboard navigation type error and coverage
emkhalid Nov 1, 2026
b2bcd30
Merge branch 'main' into fix/96225-account-switcher-keyboard-navigation
emkhalid Nov 3, 2026
691c6a4
Merge branch 'main' into fix/96225-account-switcher-keyboard-navigation
emkhalid Nov 5, 2026
b2e3467
Merge branch 'main' into fix/96225-account-switcher-keyboard-navigation
emkhalid Nov 6, 2026
2335406
Fix account switcher tab focus synchronization
emkhalid Nov 6, 2026
d58e02c
Merge branch 'main' into fix/96225-account-switcher-keyboard-navigation
emkhalid Nov 17, 2026
5d60ac5
fix: preserve native account switcher focus safeguard
emkhalid Nov 18, 2026
4d45a0a
chore: remove unrelated formatting changes from keyboard fix
emkhalid Nov 18, 2026
1c15872
Merge branch 'main' into fix/96225-account-switcher-keyboard-navigation
emkhalid Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 53 additions & 10 deletions src/components/PopoverMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import ScrollView from '@components/ScrollView';
import SearchBar from '@components/SearchBar';
import Text from '@components/Text';

import useAccessibilityAnnouncement from '@hooks/useAccessibilityAnnouncement';
import useActiveElementRole from '@hooks/useActiveElementRole';
import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
import useBottomSafeSafeAreaPaddingStyle from '@hooks/useBottomSafeSafeAreaPaddingStyle';
import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
Expand Down Expand Up @@ -427,15 +429,30 @@ function BasePopoverMenu({
const [enteredSubMenuIndexes, setEnteredSubMenuIndexes] = useState<readonly number[]>(CONST.EMPTY_ARRAY);
const isWeb = getPlatform() === CONST.PLATFORM.WEB;
const isSearchEnabled = !!searchInputOptions;
const activeElementRole = useActiveElementRole();
// Menus that do not synchronize focusedIndex can otherwise select a stale item when a different row has actual focus.
const shouldFocusedControlHandleEnter = isSearchEnabled || !shouldUpdateFocusedIndex;
const isInteractiveElementFocused =
shouldFocusedControlHandleEnter && !!activeElementRole && [CONST.ROLE.BUTTON, CONST.ROLE.CHECKBOX, CONST.ROLE.SWITCH].some((role) => role === activeElementRole);
const [isSearchInputFocused, setIsSearchInputFocused] = useState(false);
const [arrowFocusedItemAnnouncement, setArrowFocusedItemAnnouncement] = useState({message: '', key: 0});
const scrollViewRef = useRef<ComponentRef<typeof ScrollView>>(null);
const rowLayoutsRef = useRef(new Map<number, {height: number; y: number}>());
const scrollOffsetRef = useRef(0);
const scrollViewHeightRef = useRef(0);
const scrollFocusedRowIntoView = (index: number, shouldScroll: boolean) => {
const handleFocusedIndexChange = (index: number, shouldScroll: boolean) => {
if (!isSearchEnabled || !shouldScroll) {
return;
}
if (isWeb && isSearchInputFocused) {
const focusedItem = currentMenuItems.at(index);
if (focusedItem) {
const message = [focusedItem.text, focusedItem.description, focusedItem.badgeText]
.filter((value): value is string => typeof value === 'string' && value.length > 0)
.join(', ');
setArrowFocusedItemAnnouncement((previousAnnouncement) => ({message, key: previousAnnouncement.key + 1}));
}
}
const rowLayout = rowLayoutsRef.current.get(index);
if (!rowLayout || scrollViewHeightRef.current === 0) {
return;
Expand All @@ -451,11 +468,19 @@ function BasePopoverMenu({
});
}
};
const [hasKeyBeenPressed, setHasKeyBeenPressed] = useState(false);
const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({
initialFocusedIndex: currentMenuItemsFocusedIndex,
maxIndex: currentMenuItems.length - 1,
isActive: isVisible,
onFocusedIndexChange: scrollFocusedRowIntoView,
onFocusedIndexChange: handleFocusedIndexChange,
setHasKeyBeenPressed: isSearchEnabled ? () => setHasKeyBeenPressed(true) : undefined,
});
useAccessibilityAnnouncement(arrowFocusedItemAnnouncement.message, isWeb && isVisible && isSearchInputFocused && !!arrowFocusedItemAnnouncement.message, {
shouldAnnounceOnNative: false,
shouldAnnounceOnWeb: true,
announcementKey: arrowFocusedItemAnnouncement.key,
politeness: 'polite',
});
const expensifyIcons = useMemoizedLazyExpensifyIcons(['BackArrow', 'ReceiptScan', 'MoneyCircle']);
const prevMenuItems = usePrevious(menuItems);
Expand All @@ -474,7 +499,6 @@ function BasePopoverMenu({
}
}

const [hasKeyBeenPressed, setHasKeyBeenPressed] = useState(false);
const {
effectiveRestoreFocusType,
handleModalHide: handleFocusManagementModalHide,
Expand All @@ -496,14 +520,20 @@ function BasePopoverMenu({
};

const isRadioButtonMode = enteredSubMenuIndexes.length === 0 ? shouldShowRadioButton : !!getPreviousSubMenu().at(enteredSubMenuIndexes.at(-1) ?? -1)?.shouldShowRadioButton;

// Browser row focus must follow Tab navigation, while native menus keep the caller's touch-focus safeguard.
const shouldUpdateFocusedIndexOnRowFocus = shouldUpdateFocusedIndex || (isWeb && (isSearchEnabled || (isRadioButtonMode && hasKeyBeenPressed)));
// In radio-button mode, suppress the visual highlight until the user starts navigating,
// even though the selected item is already focused (for immediate Enter/arrow support).
useEffect(() => {
if (!isVisible || !isRadioButtonMode) {
return;
}
const handleKeyDown = (e: KeyboardEvent) => {
// Native Tab focus must finish before a searchable menu updates its logical focus.
// Otherwise, focus synchronization moves to the selected row first and the browser advances past it.
if (isSearchEnabled && e.key === CONST.KEYBOARD_SHORTCUTS.TAB.shortcutKey) {
return;
}
const isNavigationKey = [
CONST.KEYBOARD_SHORTCUTS.ARROW_UP,
CONST.KEYBOARD_SHORTCUTS.ARROW_DOWN,
Expand All @@ -518,7 +548,7 @@ function BasePopoverMenu({
};
addKeyDownPressListener(handleKeyDown);
return () => removeKeyDownPressListener(handleKeyDown);
}, [isVisible, isRadioButtonMode]);
}, [isVisible, isRadioButtonMode, isSearchEnabled]);

const selectItem = (index: number, event?: GestureResponderEvent | KeyboardEvent) => {
const selectedItem = currentMenuItems.at(index);
Expand Down Expand Up @@ -633,7 +663,7 @@ function BasePopoverMenu({
shouldShowRightIcon={!!item.rightIcon}
brickRoadIndicator={item.brickRoadIndicator}
onFocus={() => {
if (!shouldUpdateFocusedIndex) {
if (!shouldUpdateFocusedIndexOnRowFocus) {
return;
}
setFocusedIndex(menuIndex);
Expand Down Expand Up @@ -704,7 +734,7 @@ function BasePopoverMenu({
// Keep focus on a stay-open item (e.g. an inline toggle) so the next arrow key continues from it; otherwise reset.
setFocusedIndex(staysOpenOnSelect ? focusedIndex : -1);
},
{isActive: isVisible},
{isActive: isVisible && !isInteractiveElementFocused},
);

const keyboardShortcutSpaceCallback = (e?: GestureResponderEvent | KeyboardEvent) => {
Expand Down Expand Up @@ -757,7 +787,12 @@ function BasePopoverMenu({
setEnteredSubMenuIndexes(CONST.EMPTY_ARRAY);
setCurrentMenuItems(menuItems);
if (isSearchEnabled) {
rowLayoutsRef.current.clear();
// Rows reused after filtering may not emit another onLayout event, so preserve measurements for the remaining visual positions.
for (const rowIndex of rowLayoutsRef.current.keys()) {
if (rowIndex >= menuItems.length) {
rowLayoutsRef.current.delete(rowIndex);
}
}
scrollOffsetRef.current = 0;
scrollViewRef.current?.scrollTo({y: 0, animated: false});
setFocusedIndex(menuItems.length > 0 ? 0 : -1);
Expand Down Expand Up @@ -888,8 +923,16 @@ function BasePopoverMenu({
label={searchInputOptions.label}
inputValue={searchInputOptions.value}
onChangeText={searchInputOptions.onChangeText}
onFocus={() => setIsSearchInputFocused(true)}
onBlur={() => setIsSearchInputFocused(false)}
onFocus={() => {
setArrowFocusedItemAnnouncement((previousAnnouncement) => ({...previousAnnouncement, message: ''}));
setIsSearchInputFocused(true);
}}
onBlur={() => {
// Native focus becomes the source of truth after leaving search, so an earlier arrow highlight must not redirect Tab.
setHasKeyBeenPressed(false);
setArrowFocusedItemAnnouncement((previousAnnouncement) => ({...previousAnnouncement, message: ''}));
setIsSearchInputFocused(false);
}}
shouldShowEmptyState={searchInputOptions.shouldShowEmptyState}
shouldShowIcon={false}
style={[styles.mw100, searchInputOptions.style]}
Expand Down
1 change: 1 addition & 0 deletions src/pages/settings/InitialSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
onScroll={onScroll}
scrollEventThrottle={CONST.TIMING.MIN_SMOOTH_SCROLL_EVENT_THROTTLE}
{...tabRootScrollProps}
keyboardShouldPersistTaps="always"
>
{shouldScrollMainHeader && topBar}
{headerContent}
Expand Down
1 change: 1 addition & 0 deletions tests/ui/InitialSettingsPageTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ describe('InitialSettingsPage - scrolling', () => {

// The account switcher's tooltip is anchored inside this list, so the page has to announce scrolls.
const scrollView = screen.UNSAFE_getByType(ScrollView);
expect(scrollView.props.keyboardShouldPersistTaps).toBe('always');
fireEvent.scroll(scrollView, {
nativeEvent: {
contentOffset: {y: 120, x: 0},
Expand Down
Loading
Loading