From 2e3aceeb842d17590984c606fa02fe195a7f23b1 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Sun, 15 Nov 2026 07:22:48 +0530 Subject: [PATCH 1/6] Render left navigation destinations as real links Add a linkRoute prop to GenericPressable that renders the route as an href on web. A plain click prevents the browser navigation and runs the in-app onPress, while Cmd/Ctrl clicks are left to the browser so the destination opens in a new tab. Right-click "Open link in new tab" and middle-click work through the native anchor. Use it for every destination in NavigationTabBar and FlatNavigationBar: logo, Home, Inbox, Spend, Insights, Workspaces and Account. Signed-off-by: krishna2323 --- .../FlatNavigationBar/FlatNavItem.tsx | 6 ++ .../FlatNavigationBar/FlatNavLogo.tsx | 2 + .../Navigation/FlatNavigationBar/index.tsx | 9 ++ .../NavigationTabBar/InboxTabButton.tsx | 3 + .../NavigationTabBar/InsightsTabButton.tsx | 3 + .../NavigationTabBar/SearchTabButton.tsx | 4 + .../NavigationTabBar/WorkspacesTabButton.tsx | 3 + .../Navigation/NavigationTabBar/index.tsx | 4 + .../useStoredSearchTabRoute.ts | 17 ++++ .../implementation/BaseGenericPressable.tsx | 26 +++++- .../Pressable/GenericPressable/types.ts | 4 + .../inbox/sidebar/NavigationTabBarAvatar.tsx | 2 + tests/unit/PressableLinkRouteTest.tsx | 82 +++++++++++++++++++ 13 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 src/components/Navigation/NavigationTabBar/useStoredSearchTabRoute.ts create mode 100644 tests/unit/PressableLinkRouteTest.tsx diff --git a/src/components/Navigation/FlatNavigationBar/FlatNavItem.tsx b/src/components/Navigation/FlatNavigationBar/FlatNavItem.tsx index c4d38bf6bb05..7f721ea47b62 100644 --- a/src/components/Navigation/FlatNavigationBar/FlatNavItem.tsx +++ b/src/components/Navigation/FlatNavigationBar/FlatNavItem.tsx @@ -11,6 +11,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import variables from '@styles/variables'; import CONST from '@src/CONST'; +import type {Route} from '@src/ROUTES'; import type IconAsset from '@src/types/utils/IconAsset'; import type {SentryLabel} from '@src/types/utils/SentryLabel'; @@ -50,6 +51,9 @@ type FlatNavItemProps = { onPress: () => void; + /** Route of the destination, so the row can be opened in a new browser tab */ + linkRoute: Route; + /** Called when the pointer moves onto the row */ onHoverIn?: () => void; @@ -70,6 +74,7 @@ function FlatNavItem({ accessibilityLabel, sentryLabel, onPress, + linkRoute, onHoverIn, onHoverOut, }: FlatNavItemProps) { @@ -90,6 +95,7 @@ function FlatNavItem({ return ( setIsSearchTabHovered(true)} onHoverOut={() => setIsSearchTabHovered(false)} /> @@ -237,6 +243,7 @@ function FlatNavigationBar({selectedTab}: FlatNavigationBarProps) { isSelected={selectedTab === NAVIGATION_TABS.INSIGHTS} sentryLabel={CONST.SENTRY_LABEL.NAVIGATION_TAB_BAR.INSIGHTS} onPress={navigateToInsights} + linkRoute={ROUTES.INSIGHTS.getRoute(CONST.INSIGHTS.DASHBOARD.SPEND)} /> @@ -274,6 +282,7 @@ function FlatNavigationBar({selectedTab}: FlatNavigationBarProps) { accessibilityLabel={getTabAccessibilityLabel(`${accountLabel}, ${translate('sidebarScreen.buttonMySettings')}`, !!accountStatus, translate)} sentryLabel={CONST.SENTRY_LABEL.NAVIGATION_TAB_BAR.ACCOUNT} onPress={navigateToAccount} + linkRoute={ROUTES.SETTINGS} /> diff --git a/src/components/Navigation/NavigationTabBar/InboxTabButton.tsx b/src/components/Navigation/NavigationTabBar/InboxTabButton.tsx index 533028574eae..e91b55ea8f12 100644 --- a/src/components/Navigation/NavigationTabBar/InboxTabButton.tsx +++ b/src/components/Navigation/NavigationTabBar/InboxTabButton.tsx @@ -6,6 +6,7 @@ import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import CONST from '@src/CONST'; +import ROUTES from '@src/ROUTES'; import type {ValueOf} from 'type-fest'; @@ -40,6 +41,7 @@ function WideInboxTabButton({selectedTab, statusIndicatorColor, accessibilityLab return ( ; @@ -27,6 +28,7 @@ function SearchTabButton({selectedTab, isWideLayout}: SearchTabButtonProps) { const expensifyIcons = useMemoizedLazyExpensifyIcons(['ReceiptMultiple']); const searchAccessibilityState = {selected: selectedTab === NAVIGATION_TABS.SEARCH}; const navigateToSearch = useSearchTabNavigation(selectedTab === NAVIGATION_TABS.SEARCH); + const searchTabRoute = useStoredSearchTabRoute(); // The wide button gets no hover out when it goes away while hovered, on a switch to the narrow layout or an unmount. useEffect(() => () => setIsSearchTabHovered(false), [isWideLayout]); @@ -35,6 +37,7 @@ function SearchTabButton({selectedTab, isWideLayout}: SearchTabButtonProps) { return ( @@ -84,6 +86,7 @@ function NavigationTabBar({selectedTab, shouldShowFloatingButtons = true}: Navig [styles.leftNavigationTabBarItem, hovered && styles.navigationTabBarItemHovered]} @@ -140,6 +143,7 @@ function NavigationTabBar({selectedTab, shouldShowFloatingButtons = true}: Navig > singleExecution(onPressHandler)(event); + const pressOnce = (event?: GestureResponderEvent) => singleExecution(onPressHandler)(event); + + // The browser follows the href unless the click is prevented, so only Cmd or Ctrl clicks on an enabled link reach it and open a new tab. + const pressLink = (event?: GestureResponderEvent) => { + if (!isDisabled && isModifiedMousePress(event)) { + return; + } + event?.preventDefault(); + if (isDisabled) { + return; + } + pressOnce(event); + }; + + const getPressHandler = () => { + if (linkRoute) { + return pressLink; + } + return !isDisabled ? pressOnce : undefined; + }; const {shortcutKey, descriptionKey, modifiers} = keyboardShortcut ?? {}; useKeyboardShortcut({shortcutKey, descriptionKey, modifiers} as ValueOf, onKeyboardShortcutPressHandler, { @@ -184,7 +205,7 @@ function GenericPressable({ onLayout={shouldUseAutoHitSlop ? onLayout : undefined} ref={composedRef} disabled={fullDisabled || undefined} - onPress={!isDisabled ? pressOnce : undefined} + onPress={getPressHandler()} onLongPress={!isDisabled && onLongPress ? onLongPressHandler : undefined} onKeyDown={!isDisabled ? handleKeyDown : undefined} onPressIn={!isDisabled ? onPressIn : undefined} @@ -215,6 +236,7 @@ function GenericPressable({ onAccessibilityTap={!isDisabled ? voidOnPressHandler : undefined} accessible={accessible} fsClass={forwardedFSClass} + href={linkRoute && !fullDisabled ? `/${linkRoute}` : undefined} {...rest} onHoverOut={(event) => { if (event?.type === 'pointerenter' || event?.type === 'mouseenter') { diff --git a/src/components/Pressable/GenericPressable/types.ts b/src/components/Pressable/GenericPressable/types.ts index 7796196c3c86..4268a0622559 100644 --- a/src/components/Pressable/GenericPressable/types.ts +++ b/src/components/Pressable/GenericPressable/types.ts @@ -3,6 +3,7 @@ import type {ForwardedFSClassProps} from '@libs/Fullstory/types'; import type {Shortcut} from '@libs/KeyboardShortcut'; import type CONST from '@src/CONST'; +import type {Route} from '@src/ROUTES'; import type WithSentryLabel from '@src/types/utils/SentryLabel'; import type {ComponentRef, ForwardedRef} from 'react'; @@ -166,6 +167,9 @@ type PressableProps = RNPressableProps & */ shouldAllowTextSelection?: boolean; + /** Renders the pressable as a link to this route on web, so it can be opened in a new tab */ + linkRoute?: Route; + ref?: PressableRef; }; diff --git a/src/pages/inbox/sidebar/NavigationTabBarAvatar.tsx b/src/pages/inbox/sidebar/NavigationTabBarAvatar.tsx index 4625cec84305..759ab9f1aff7 100644 --- a/src/pages/inbox/sidebar/NavigationTabBarAvatar.tsx +++ b/src/pages/inbox/sidebar/NavigationTabBarAvatar.tsx @@ -9,6 +9,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import CONST from '@src/CONST'; +import ROUTES from '@src/ROUTES'; import type {StyleProp, ViewStyle} from 'react-native'; @@ -36,6 +37,7 @@ function NavigationTabBarAvatar({onPress, isSelected = false, style}: Navigation return ( jest.requireActual>('@libs/Navigation/helpers/openInternalRouteInNewTab/index.ts')); + +const TEST_ID = 'link-pressable'; + +function renderLinkPressable(onPress: () => void, isDisabled = false) { + render( + + Settings + , + ); +} + +describe('Pressable with linkRoute', () => { + it('renders the route as an absolute href', () => { + // Given a pressable linking to the settings route + renderLinkPressable(jest.fn()); + + // Then the href starts at the site root, so it does not resolve against the current page's path + expect(screen.getByTestId(TEST_ID).props.href).toBe(`/${ROUTES.SETTINGS}`); + }); + + it('navigates in the app and stops the browser from loading the href on a plain click', () => { + // Given a pressable linking to the settings route + const onPress = jest.fn(); + const preventDefault = jest.fn(); + renderLinkPressable(onPress); + + // When it is clicked without a modifier key + fireEvent.press(screen.getByTestId(TEST_ID), {nativeEvent: {button: 0}, preventDefault}); + + // Then the browser's page load is prevented and the in-app handler runs instead + expect(preventDefault).toHaveBeenCalled(); + expect(onPress).toHaveBeenCalled(); + }); + + it('leaves a Cmd click to the browser so the route opens in a new tab', () => { + // Given a pressable linking to the settings route + const onPress = jest.fn(); + const preventDefault = jest.fn(); + renderLinkPressable(onPress); + + // When it is clicked with the Cmd key held + fireEvent.press(screen.getByTestId(TEST_ID), {nativeEvent: {button: 0, metaKey: true}, preventDefault}); + + // Then the current tab does not navigate and the browser keeps its default new tab behavior + expect(preventDefault).not.toHaveBeenCalled(); + expect(onPress).not.toHaveBeenCalled(); + }); + + it('does not follow the href when disabled', () => { + // Given a disabled pressable linking to the settings route + const onPress = jest.fn(); + const preventDefault = jest.fn(); + renderLinkPressable(onPress, true); + + // When it is clicked with the Ctrl key held + fireEvent.press(screen.getByTestId(TEST_ID), {nativeEvent: {button: 0, ctrlKey: true}, preventDefault}); + + // Then neither the browser nor the app navigates + expect(preventDefault).toHaveBeenCalled(); + expect(onPress).not.toHaveBeenCalled(); + }); +}); From e85eee240af13f3d2d4e7b5f7fb8063ac4dac558 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Sun, 15 Nov 2026 07:23:49 +0530 Subject: [PATCH 2/6] Address coding standards review on navigation links Select only queryJSON and searchKey for the stored Spend route, so the tab bars don't re-render when search pagination fields change. Share the default Insights route between the tab bars and getInsightsTabRoute. Add the missing When comment to the link test. Signed-off-by: krishna2323 --- src/components/Navigation/FlatNavigationBar/index.tsx | 3 ++- .../Navigation/NavigationTabBar/InsightsTabButton.tsx | 6 +++--- .../Navigation/NavigationTabBar/getInsightsTabRoute.ts | 6 +++++- .../NavigationTabBar/useStoredSearchTabRoute.ts | 9 ++++++++- tests/unit/PressableLinkRouteTest.tsx | 1 + 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/components/Navigation/FlatNavigationBar/index.tsx b/src/components/Navigation/FlatNavigationBar/index.tsx index 9a3d1cfb9d83..d8b7a02b0f86 100644 --- a/src/components/Navigation/FlatNavigationBar/index.tsx +++ b/src/components/Navigation/FlatNavigationBar/index.tsx @@ -2,6 +2,7 @@ import AccountNavigationAvatar from '@components/Avatar/AccountNavigationAvatar' import EnvironmentBadge from '@components/EnvironmentBadge'; import Hoverable from '@components/Hoverable'; import DebugTabView from '@components/Navigation/DebugTabView'; +import {DEFAULT_INSIGHTS_TAB_ROUTE} from '@components/Navigation/NavigationTabBar/getInsightsTabRoute'; import getTabAccessibilityLabel from '@components/Navigation/NavigationTabBar/getTabAccessibilityLabel'; import NAVIGATION_TABS from '@components/Navigation/NavigationTabBar/NAVIGATION_TABS'; import useAccountTabNavigation from '@components/Navigation/NavigationTabBar/useAccountTabNavigation'; @@ -243,7 +244,7 @@ function FlatNavigationBar({selectedTab}: FlatNavigationBarProps) { isSelected={selectedTab === NAVIGATION_TABS.INSIGHTS} sentryLabel={CONST.SENTRY_LABEL.NAVIGATION_TAB_BAR.INSIGHTS} onPress={navigateToInsights} - linkRoute={ROUTES.INSIGHTS.getRoute(CONST.INSIGHTS.DASHBOARD.SPEND)} + linkRoute={DEFAULT_INSIGHTS_TAB_ROUTE} /> route.name === SCREENS.INSIGHTS)?.params; @@ -16,7 +19,8 @@ function getInsightsTabRoute(rootState: NavigationState | undefined, accessibleD return ROUTES.INSIGHTS.getRoute(lastDashboardID); } - return ROUTES.INSIGHTS.getRoute(CONST.INSIGHTS.DASHBOARD.SPEND); + return DEFAULT_INSIGHTS_TAB_ROUTE; } export default getInsightsTabRoute; +export {DEFAULT_INSIGHTS_TAB_ROUTE}; diff --git a/src/components/Navigation/NavigationTabBar/useStoredSearchTabRoute.ts b/src/components/Navigation/NavigationTabBar/useStoredSearchTabRoute.ts index ded78d55f9bf..1e0966849464 100644 --- a/src/components/Navigation/NavigationTabBar/useStoredSearchTabRoute.ts +++ b/src/components/Navigation/NavigationTabBar/useStoredSearchTabRoute.ts @@ -3,12 +3,19 @@ import useOnyx from '@hooks/useOnyx'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import {lastExpensesSearchQuerySelector} from '@src/selectors/SearchFilters'; +import type LastSearchParams from '@src/types/onyx/ReportNavigation'; + +import type {OnyxEntry} from 'react-native-onyx'; import {getStoredSearchTabParams} from './getSearchTabRoute'; +function lastSearchQuerySelector(lastSearchParams: OnyxEntry): LastSearchParams { + return {queryJSON: lastSearchParams?.queryJSON, searchKey: lastSearchParams?.searchKey}; +} + /** Returns the Spend route a new browser tab opens. A new tab has no navigation history, so it starts from the last search kept in Onyx. */ function useStoredSearchTabRoute() { - const [lastSearchParams] = useOnyx(ONYXKEYS.REPORT_NAVIGATION_LAST_SEARCH_QUERY); + const [lastSearchParams] = useOnyx(ONYXKEYS.REPORT_NAVIGATION_LAST_SEARCH_QUERY, {selector: lastSearchQuerySelector}); const [lastExpensesSearchQuery] = useOnyx(ONYXKEYS.SEARCH_FILTERS, {selector: lastExpensesSearchQuerySelector}); return ROUTES.SEARCH_ROOT.getRoute(getStoredSearchTabParams(lastSearchParams, lastExpensesSearchQuery)); diff --git a/tests/unit/PressableLinkRouteTest.tsx b/tests/unit/PressableLinkRouteTest.tsx index 8bfe3731cb32..c37307557f84 100644 --- a/tests/unit/PressableLinkRouteTest.tsx +++ b/tests/unit/PressableLinkRouteTest.tsx @@ -32,6 +32,7 @@ function renderLinkPressable(onPress: () => void, isDisabled = false) { describe('Pressable with linkRoute', () => { it('renders the route as an absolute href', () => { // Given a pressable linking to the settings route + // When it renders renderLinkPressable(jest.fn()); // Then the href starts at the site root, so it does not resolve against the current page's path From 3957abdf4bbe25849542ec3ea848341d16d8ed78 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Mon, 16 Nov 2026 01:41:19 +0530 Subject: [PATCH 3/6] Keep sidebar links behind sign-in and disabled state Anonymous users get no href on gated tabs, so a Cmd click still shows the sign-in prompt. Disabled pressables render no href, so the context menu cannot open them. Signed-off-by: krishna2323 --- .../FlatNavigationBar/FlatNavItem.tsx | 2 +- .../Navigation/FlatNavigationBar/index.tsx | 12 +++-- .../NavigationTabBar/InsightsTabButton.tsx | 6 ++- .../NavigationTabBar/SearchTabButton.tsx | 3 +- .../NavigationTabBar/WorkspacesTabButton.tsx | 6 ++- .../NavigationTabBar/useSignedInLinkRoute.ts | 18 ++++++++ .../implementation/BaseGenericPressable.tsx | 2 +- .../inbox/sidebar/NavigationTabBarAvatar.tsx | 4 +- tests/unit/PressableLinkRouteTest.tsx | 9 ++++ tests/unit/useSignedInLinkRouteTest.ts | 46 +++++++++++++++++++ 10 files changed, 96 insertions(+), 12 deletions(-) create mode 100644 src/components/Navigation/NavigationTabBar/useSignedInLinkRoute.ts create mode 100644 tests/unit/useSignedInLinkRouteTest.ts diff --git a/src/components/Navigation/FlatNavigationBar/FlatNavItem.tsx b/src/components/Navigation/FlatNavigationBar/FlatNavItem.tsx index 7f721ea47b62..e7cad6d7ddc4 100644 --- a/src/components/Navigation/FlatNavigationBar/FlatNavItem.tsx +++ b/src/components/Navigation/FlatNavigationBar/FlatNavItem.tsx @@ -52,7 +52,7 @@ type FlatNavItemProps = { onPress: () => void; /** Route of the destination, so the row can be opened in a new browser tab */ - linkRoute: Route; + linkRoute?: Route; /** Called when the pointer moves onto the row */ onHoverIn?: () => void; diff --git a/src/components/Navigation/FlatNavigationBar/index.tsx b/src/components/Navigation/FlatNavigationBar/index.tsx index d8b7a02b0f86..f87c948cab5c 100644 --- a/src/components/Navigation/FlatNavigationBar/index.tsx +++ b/src/components/Navigation/FlatNavigationBar/index.tsx @@ -9,6 +9,7 @@ import useAccountTabNavigation from '@components/Navigation/NavigationTabBar/use import useHomeTabNavigation from '@components/Navigation/NavigationTabBar/useHomeTabNavigation'; import useInsightsTabNavigation from '@components/Navigation/NavigationTabBar/useInsightsTabNavigation'; import useSearchTabNavigation from '@components/Navigation/NavigationTabBar/useSearchTabNavigation'; +import useSignedInLinkRoute from '@components/Navigation/NavigationTabBar/useSignedInLinkRoute'; import useStoredSearchTabRoute from '@components/Navigation/NavigationTabBar/useStoredSearchTabRoute'; import useWideInboxNavigation from '@components/Navigation/NavigationTabBar/useWideInboxNavigation'; import { @@ -78,7 +79,10 @@ function FlatNavigationBar({selectedTab}: FlatNavigationBarProps) { const navigateToInbox = useWideInboxNavigation(selectedTab === NAVIGATION_TABS.INBOX); const navigateToSearch = useSearchTabNavigation(selectedTab === NAVIGATION_TABS.SEARCH); - const searchTabRoute = useStoredSearchTabRoute(); + const searchTabRoute = useSignedInLinkRoute(useStoredSearchTabRoute()); + const insightsLinkRoute = useSignedInLinkRoute(DEFAULT_INSIGHTS_TAB_ROUTE); + const workspacesLinkRoute = useSignedInLinkRoute(ROUTES.WORKSPACES_LIST.route); + const accountLinkRoute = useSignedInLinkRoute(ROUTES.SETTINGS); const navigateToInsights = useInsightsTabNavigation(selectedTab === NAVIGATION_TABS.INSIGHTS); const navigateToWorkspaces = useRestoreWorkspacesTabOnNavigate(); @@ -244,7 +248,7 @@ function FlatNavigationBar({selectedTab}: FlatNavigationBarProps) { isSelected={selectedTab === NAVIGATION_TABS.INSIGHTS} sentryLabel={CONST.SENTRY_LABEL.NAVIGATION_TAB_BAR.INSIGHTS} onPress={navigateToInsights} - linkRoute={DEFAULT_INSIGHTS_TAB_ROUTE} + linkRoute={insightsLinkRoute} /> @@ -283,7 +287,7 @@ function FlatNavigationBar({selectedTab}: FlatNavigationBarProps) { accessibilityLabel={getTabAccessibilityLabel(`${accountLabel}, ${translate('sidebarScreen.buttonMySettings')}`, !!accountStatus, translate)} sentryLabel={CONST.SENTRY_LABEL.NAVIGATION_TAB_BAR.ACCOUNT} onPress={navigateToAccount} - linkRoute={ROUTES.SETTINGS} + linkRoute={accountLinkRoute} /> diff --git a/src/components/Navigation/NavigationTabBar/InsightsTabButton.tsx b/src/components/Navigation/NavigationTabBar/InsightsTabButton.tsx index 5b6d30e5044d..1a378897fd10 100644 --- a/src/components/Navigation/NavigationTabBar/InsightsTabButton.tsx +++ b/src/components/Navigation/NavigationTabBar/InsightsTabButton.tsx @@ -14,6 +14,7 @@ import {DEFAULT_INSIGHTS_TAB_ROUTE} from './getInsightsTabRoute'; import NAVIGATION_TABS from './NAVIGATION_TABS'; import TabBarItem from './TabBarItem'; import useInsightsTabNavigation from './useInsightsTabNavigation'; +import useSignedInLinkRoute from './useSignedInLinkRoute'; type InsightsTabButtonProps = { selectedTab: ValueOf; @@ -26,12 +27,13 @@ function InsightsTabButton({selectedTab, isWideLayout}: InsightsTabButtonProps) const expensifyIcons = useMemoizedLazyExpensifyIcons(['PieChart']); const isSelected = selectedTab === NAVIGATION_TABS.INSIGHTS; const navigateToInsights = useInsightsTabNavigation(isSelected); + const insightsLinkRoute = useSignedInLinkRoute(DEFAULT_INSIGHTS_TAB_ROUTE); if (isWideLayout) { return ( () => setIsSearchTabHovered(false), [isWideLayout]); diff --git a/src/components/Navigation/NavigationTabBar/WorkspacesTabButton.tsx b/src/components/Navigation/NavigationTabBar/WorkspacesTabButton.tsx index bcb46ed049b5..0ae1d3c79ab4 100644 --- a/src/components/Navigation/NavigationTabBar/WorkspacesTabButton.tsx +++ b/src/components/Navigation/NavigationTabBar/WorkspacesTabButton.tsx @@ -16,6 +16,7 @@ import React from 'react'; import getTabAccessibilityLabel from './getTabAccessibilityLabel'; import NAVIGATION_TABS from './NAVIGATION_TABS'; import TabBarItem from './TabBarItem'; +import useSignedInLinkRoute from './useSignedInLinkRoute'; type WorkspacesTabButtonProps = { selectedTab: ValueOf; @@ -29,6 +30,7 @@ function WorkspacesTabButton({selectedTab, isWideLayout}: WorkspacesTabButtonPro const {indicatorColor: workspacesTabIndicatorColor, status: workspacesTabIndicatorStatus} = useWorkspacesTabIndicatorStatus(); const navigateToWorkspaces = useRestoreWorkspacesTabOnNavigate(); + const workspacesLinkRoute = useSignedInLinkRoute(ROUTES.WORKSPACES_LIST.route); const workspacesAccessibilityState = {selected: selectedTab === NAVIGATION_TABS.WORKSPACES}; const workspacesStatusIndicatorColor = workspacesTabIndicatorStatus ? workspacesTabIndicatorColor : undefined; @@ -37,7 +39,7 @@ function WorkspacesTabButton({selectedTab, isWideLayout}: WorkspacesTabButtonPro return ( { if (event?.type === 'pointerenter' || event?.type === 'mouseenter') { diff --git a/src/pages/inbox/sidebar/NavigationTabBarAvatar.tsx b/src/pages/inbox/sidebar/NavigationTabBarAvatar.tsx index 759ab9f1aff7..063834e70ae6 100644 --- a/src/pages/inbox/sidebar/NavigationTabBarAvatar.tsx +++ b/src/pages/inbox/sidebar/NavigationTabBarAvatar.tsx @@ -1,6 +1,7 @@ import AccountNavigationAvatar from '@components/Avatar/AccountNavigationAvatar'; import getTabAccessibilityLabel from '@components/Navigation/NavigationTabBar/getTabAccessibilityLabel'; import TabBarLabel from '@components/Navigation/NavigationTabBar/TabBarLabel'; +import useSignedInLinkRoute from '@components/Navigation/NavigationTabBar/useSignedInLinkRoute'; import {PressableWithFeedback} from '@components/Pressable'; import useAccountTabIndicatorStatus from '@hooks/useAccountTabIndicatorStatus'; @@ -33,11 +34,12 @@ function NavigationTabBarAvatar({onPress, isSelected = false, style}: Navigation const {status} = useAccountTabIndicatorStatus(); const accountAccessibilityState = {selected: isSelected}; + const accountLinkRoute = useSignedInLinkRoute(ROUTES.SETTINGS); return ( { expect(onPress).not.toHaveBeenCalled(); }); + it('renders no href when disabled', () => { + // Given a disabled pressable linking to the settings route + // When it renders + renderLinkPressable(jest.fn(), true); + + // Then there is no href, so the browser context menu cannot open the route in a new tab + expect(screen.getByTestId(TEST_ID).props.href).toBeUndefined(); + }); + it('does not follow the href when disabled', () => { // Given a disabled pressable linking to the settings route const onPress = jest.fn(); diff --git a/tests/unit/useSignedInLinkRouteTest.ts b/tests/unit/useSignedInLinkRouteTest.ts new file mode 100644 index 000000000000..69add62d947a --- /dev/null +++ b/tests/unit/useSignedInLinkRouteTest.ts @@ -0,0 +1,46 @@ +import {renderHook} from '@testing-library/react-native'; + +import useSignedInLinkRoute from '@components/Navigation/NavigationTabBar/useSignedInLinkRoute'; + +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import ROUTES from '@src/ROUTES'; + +import Onyx from 'react-native-onyx'; + +import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; + +describe('useSignedInLinkRoute', () => { + beforeAll(() => { + Onyx.init({keys: ONYXKEYS}); + }); + + beforeEach(() => { + Onyx.clear(); + return waitForBatchedUpdates(); + }); + + it('returns the route for a signed in user', async () => { + // Given a signed in user + await Onyx.merge(ONYXKEYS.SESSION, {authToken: 'token', email: 'user@expensify.com'}); + await waitForBatchedUpdates(); + + // When the hook resolves the Account tab link + const {result} = renderHook(() => useSignedInLinkRoute(ROUTES.SETTINGS)); + + // Then the tab can be opened in a new browser tab + expect(result.current).toBe(ROUTES.SETTINGS); + }); + + it('returns no route for an anonymous user', async () => { + // Given an anonymous user, who must sign in before opening the Account tab + await Onyx.merge(ONYXKEYS.SESSION, {authTokenType: CONST.AUTH_TOKEN_TYPES.ANONYMOUS}); + await waitForBatchedUpdates(); + + // When the hook resolves the Account tab link + const {result} = renderHook(() => useSignedInLinkRoute(ROUTES.SETTINGS)); + + // Then there is no link, so a Cmd click cannot open the tab without the sign in prompt + expect(result.current).toBeUndefined(); + }); +}); From ce4076d02bef5fd8294188d4eabd71d9ee04d0a6 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Mon, 16 Nov 2026 20:30:11 +0530 Subject: [PATCH 4/6] Tighten navigation link behavior from review Read the session once per component for gated link routes. Share one helper for turning a route into a path. Drop the href for non-interactive pressables. Leave Shift clicks and Enter on links to the browser so they open a new window or tab like a real link. Signed-off-by: krishna2323 --- .../Navigation/FlatNavigationBar/index.tsx | 14 +++---- .../NavigationTabBar/InsightsTabButton.tsx | 3 +- .../NavigationTabBar/SearchTabButton.tsx | 3 +- .../NavigationTabBar/WorkspacesTabButton.tsx | 3 +- .../NavigationTabBar/useSignedInLinkRoute.ts | 8 ++-- .../implementation/BaseGenericPressable.tsx | 14 ++++--- src/libs/Navigation/helpers/getRoutePath.ts | 8 ++++ .../openInternalRouteInNewTab/index.native.ts | 4 +- .../openInternalRouteInNewTab/index.ts | 22 +++++++--- .../openInternalRouteInNewTab/types.ts | 3 +- .../inbox/sidebar/NavigationTabBarAvatar.tsx | 3 +- tests/unit/PressableLinkRouteTest.tsx | 40 ++++++++++++++++++- tests/unit/useSignedInLinkRouteTest.ts | 8 ++-- 13 files changed, 100 insertions(+), 33 deletions(-) create mode 100644 src/libs/Navigation/helpers/getRoutePath.ts diff --git a/src/components/Navigation/FlatNavigationBar/index.tsx b/src/components/Navigation/FlatNavigationBar/index.tsx index f87c948cab5c..d8ae8f686a4d 100644 --- a/src/components/Navigation/FlatNavigationBar/index.tsx +++ b/src/components/Navigation/FlatNavigationBar/index.tsx @@ -79,10 +79,8 @@ function FlatNavigationBar({selectedTab}: FlatNavigationBarProps) { const navigateToInbox = useWideInboxNavigation(selectedTab === NAVIGATION_TABS.INBOX); const navigateToSearch = useSearchTabNavigation(selectedTab === NAVIGATION_TABS.SEARCH); - const searchTabRoute = useSignedInLinkRoute(useStoredSearchTabRoute()); - const insightsLinkRoute = useSignedInLinkRoute(DEFAULT_INSIGHTS_TAB_ROUTE); - const workspacesLinkRoute = useSignedInLinkRoute(ROUTES.WORKSPACES_LIST.route); - const accountLinkRoute = useSignedInLinkRoute(ROUTES.SETTINGS); + const getSignedInLinkRoute = useSignedInLinkRoute(); + const storedSearchTabRoute = useStoredSearchTabRoute(); const navigateToInsights = useInsightsTabNavigation(selectedTab === NAVIGATION_TABS.INSIGHTS); const navigateToWorkspaces = useRestoreWorkspacesTabOnNavigate(); @@ -237,7 +235,7 @@ function FlatNavigationBar({selectedTab}: FlatNavigationBarProps) { isSelected={selectedTab === NAVIGATION_TABS.SEARCH} sentryLabel={CONST.SENTRY_LABEL.NAVIGATION_TAB_BAR.REPORTS} onPress={navigateToSearch} - linkRoute={searchTabRoute} + linkRoute={getSignedInLinkRoute(storedSearchTabRoute)} onHoverIn={() => setIsSearchTabHovered(true)} onHoverOut={() => setIsSearchTabHovered(false)} /> @@ -248,7 +246,7 @@ function FlatNavigationBar({selectedTab}: FlatNavigationBarProps) { isSelected={selectedTab === NAVIGATION_TABS.INSIGHTS} sentryLabel={CONST.SENTRY_LABEL.NAVIGATION_TAB_BAR.INSIGHTS} onPress={navigateToInsights} - linkRoute={insightsLinkRoute} + linkRoute={getSignedInLinkRoute(DEFAULT_INSIGHTS_TAB_ROUTE)} /> @@ -287,7 +285,7 @@ function FlatNavigationBar({selectedTab}: FlatNavigationBarProps) { accessibilityLabel={getTabAccessibilityLabel(`${accountLabel}, ${translate('sidebarScreen.buttonMySettings')}`, !!accountStatus, translate)} sentryLabel={CONST.SENTRY_LABEL.NAVIGATION_TAB_BAR.ACCOUNT} onPress={navigateToAccount} - linkRoute={accountLinkRoute} + linkRoute={getSignedInLinkRoute(ROUTES.SETTINGS)} /> diff --git a/src/components/Navigation/NavigationTabBar/InsightsTabButton.tsx b/src/components/Navigation/NavigationTabBar/InsightsTabButton.tsx index 1a378897fd10..fe3105b5a11d 100644 --- a/src/components/Navigation/NavigationTabBar/InsightsTabButton.tsx +++ b/src/components/Navigation/NavigationTabBar/InsightsTabButton.tsx @@ -27,7 +27,8 @@ function InsightsTabButton({selectedTab, isWideLayout}: InsightsTabButtonProps) const expensifyIcons = useMemoizedLazyExpensifyIcons(['PieChart']); const isSelected = selectedTab === NAVIGATION_TABS.INSIGHTS; const navigateToInsights = useInsightsTabNavigation(isSelected); - const insightsLinkRoute = useSignedInLinkRoute(DEFAULT_INSIGHTS_TAB_ROUTE); + const getSignedInLinkRoute = useSignedInLinkRoute(); + const insightsLinkRoute = getSignedInLinkRoute(DEFAULT_INSIGHTS_TAB_ROUTE); if (isWideLayout) { return ( diff --git a/src/components/Navigation/NavigationTabBar/SearchTabButton.tsx b/src/components/Navigation/NavigationTabBar/SearchTabButton.tsx index ba687f58c6a7..c737a85021fc 100644 --- a/src/components/Navigation/NavigationTabBar/SearchTabButton.tsx +++ b/src/components/Navigation/NavigationTabBar/SearchTabButton.tsx @@ -29,7 +29,8 @@ function SearchTabButton({selectedTab, isWideLayout}: SearchTabButtonProps) { const expensifyIcons = useMemoizedLazyExpensifyIcons(['ReceiptMultiple']); const searchAccessibilityState = {selected: selectedTab === NAVIGATION_TABS.SEARCH}; const navigateToSearch = useSearchTabNavigation(selectedTab === NAVIGATION_TABS.SEARCH); - const searchTabRoute = useSignedInLinkRoute(useStoredSearchTabRoute()); + const getSignedInLinkRoute = useSignedInLinkRoute(); + const searchTabRoute = getSignedInLinkRoute(useStoredSearchTabRoute()); // The wide button gets no hover out when it goes away while hovered, on a switch to the narrow layout or an unmount. useEffect(() => () => setIsSearchTabHovered(false), [isWideLayout]); diff --git a/src/components/Navigation/NavigationTabBar/WorkspacesTabButton.tsx b/src/components/Navigation/NavigationTabBar/WorkspacesTabButton.tsx index 0ae1d3c79ab4..bb9042998929 100644 --- a/src/components/Navigation/NavigationTabBar/WorkspacesTabButton.tsx +++ b/src/components/Navigation/NavigationTabBar/WorkspacesTabButton.tsx @@ -30,7 +30,8 @@ function WorkspacesTabButton({selectedTab, isWideLayout}: WorkspacesTabButtonPro const {indicatorColor: workspacesTabIndicatorColor, status: workspacesTabIndicatorStatus} = useWorkspacesTabIndicatorStatus(); const navigateToWorkspaces = useRestoreWorkspacesTabOnNavigate(); - const workspacesLinkRoute = useSignedInLinkRoute(ROUTES.WORKSPACES_LIST.route); + const getSignedInLinkRoute = useSignedInLinkRoute(); + const workspacesLinkRoute = getSignedInLinkRoute(ROUTES.WORKSPACES_LIST.route); const workspacesAccessibilityState = {selected: selectedTab === NAVIGATION_TABS.WORKSPACES}; const workspacesStatusIndicatorColor = workspacesTabIndicatorStatus ? workspacesTabIndicatorColor : undefined; diff --git a/src/components/Navigation/NavigationTabBar/useSignedInLinkRoute.ts b/src/components/Navigation/NavigationTabBar/useSignedInLinkRoute.ts index e9dde2f76ee4..8163ac187267 100644 --- a/src/components/Navigation/NavigationTabBar/useSignedInLinkRoute.ts +++ b/src/components/Navigation/NavigationTabBar/useSignedInLinkRoute.ts @@ -6,13 +6,13 @@ import type {Route} from '@src/ROUTES'; import {isAnonymousSessionSelector} from '@selectors/Session'; /** - * Returns the route a tab links to, or nothing for anonymous users. Their press handler asks them to sign in, - * which a link opened in a new browser tab would skip. + * Returns a function giving the route a tab links to, or nothing for anonymous users. Their press handler asks them + * to sign in, which a link opened in a new browser tab would skip. */ -function useSignedInLinkRoute(route: Route): Route | undefined { +function useSignedInLinkRoute(): (route: Route) => Route | undefined { const [isAnonymousUser = false] = useOnyx(ONYXKEYS.SESSION, {selector: isAnonymousSessionSelector}); - return isAnonymousUser ? undefined : route; + return (route: Route) => (isAnonymousUser ? undefined : route); } export default useSignedInLinkRoute; diff --git a/src/components/Pressable/GenericPressable/implementation/BaseGenericPressable.tsx b/src/components/Pressable/GenericPressable/implementation/BaseGenericPressable.tsx index 7c43e85e2242..0fc6630ba7a1 100644 --- a/src/components/Pressable/GenericPressable/implementation/BaseGenericPressable.tsx +++ b/src/components/Pressable/GenericPressable/implementation/BaseGenericPressable.tsx @@ -9,7 +9,8 @@ import useThemeStyles from '@hooks/useThemeStyles'; import Accessibility from '@libs/Accessibility'; import HapticFeedback from '@libs/HapticFeedback'; import mergeRefs from '@libs/mergeRefs'; -import {isModifiedMousePress} from '@libs/Navigation/helpers/openInternalRouteInNewTab'; +import getRoutePath from '@libs/Navigation/helpers/getRoutePath'; +import {isNewTabOrWindowMousePress} from '@libs/Navigation/helpers/openInternalRouteInNewTab'; import {notifyPressedTrigger, registerPressable} from '@libs/NavigationFocusReturn'; import CONST from '@src/CONST'; @@ -153,9 +154,11 @@ function GenericPressable({ const pressOnce = (event?: GestureResponderEvent) => singleExecution(onPressHandler)(event); - // The browser follows the href unless the click is prevented, so only Cmd or Ctrl clicks on an enabled link reach it and open a new tab. + const hasHref = !!linkRoute && !isDisabled && !fullDisabled && interactive; + + // The browser follows the href unless the click is prevented, so only Cmd, Ctrl or Shift clicks on an enabled link reach it and open a new tab or window. const pressLink = (event?: GestureResponderEvent) => { - if (!isDisabled && isModifiedMousePress(event)) { + if (hasHref && isNewTabOrWindowMousePress(event)) { return; } event?.preventDefault(); @@ -186,6 +189,7 @@ function GenericPressable({ * If a custom onKeyDown handler is provided, it delegates to that handler. * Otherwise, for elements with role="link", it triggers onPress when Enter is pressed * to comply with W3C APG Link Pattern (https://www.w3.org/WAI/ARIA/apg/patterns/link/). + * An element with an href is skipped, because the browser turns Enter into a click that keeps its modifier keys for pressLink. */ const handleKeyDown = (event: React.KeyboardEvent) => { if (onKeyDown) { @@ -193,7 +197,7 @@ function GenericPressable({ return; } - if (isRoleLink && event.key === CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey) { + if (isRoleLink && !hasHref && event.key === CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey) { event.preventDefault(); onPressHandler(event.nativeEvent as unknown as KeyboardEvent); } @@ -236,7 +240,7 @@ function GenericPressable({ onAccessibilityTap={!isDisabled ? voidOnPressHandler : undefined} accessible={accessible} fsClass={forwardedFSClass} - href={linkRoute && !isDisabled && !fullDisabled ? `/${linkRoute}` : undefined} + href={hasHref && linkRoute ? getRoutePath(linkRoute) : undefined} {...rest} onHoverOut={(event) => { if (event?.type === 'pointerenter' || event?.type === 'mouseenter') { diff --git a/src/libs/Navigation/helpers/getRoutePath.ts b/src/libs/Navigation/helpers/getRoutePath.ts new file mode 100644 index 000000000000..42723d30f541 --- /dev/null +++ b/src/libs/Navigation/helpers/getRoutePath.ts @@ -0,0 +1,8 @@ +import type {Route} from '@src/ROUTES'; + +/** Starts the route at the site root, so a link to it does not resolve against the current page's path. */ +function getRoutePath(route: Route): string { + return route.startsWith('/') ? route : `/${route}`; +} + +export default getRoutePath; diff --git a/src/libs/Navigation/helpers/openInternalRouteInNewTab/index.native.ts b/src/libs/Navigation/helpers/openInternalRouteInNewTab/index.native.ts index 1c079166b48f..9949ad77a6b1 100644 --- a/src/libs/Navigation/helpers/openInternalRouteInNewTab/index.native.ts +++ b/src/libs/Navigation/helpers/openInternalRouteInNewTab/index.native.ts @@ -4,8 +4,10 @@ import type {ModifiedMouseEvent} from './types'; const isModifiedMousePress: (event?: ModifiedMouseEvent) => boolean = () => false; +const isNewTabOrWindowMousePress: (event?: ModifiedMouseEvent) => boolean = () => false; + const openInternalRouteInNewTab: (route: Route, event?: ModifiedMouseEvent) => boolean = () => false; -export {isModifiedMousePress}; +export {isModifiedMousePress, isNewTabOrWindowMousePress}; export type {ModifiedMouseEvent}; export default openInternalRouteInNewTab; diff --git a/src/libs/Navigation/helpers/openInternalRouteInNewTab/index.ts b/src/libs/Navigation/helpers/openInternalRouteInNewTab/index.ts index e0bbce2b3b36..8c2ee58a1246 100644 --- a/src/libs/Navigation/helpers/openInternalRouteInNewTab/index.ts +++ b/src/libs/Navigation/helpers/openInternalRouteInNewTab/index.ts @@ -1,20 +1,32 @@ +import getRoutePath from '@libs/Navigation/helpers/getRoutePath'; + import type {Route} from '@src/ROUTES'; import type {ModifiedMouseEvent, ModifiedMouseEventSource} from './types'; function getRouteURL(route: Route) { - return new URL(route.startsWith('/') ? route : `/${route}`, window.location.origin).toString(); + return new URL(getRoutePath(route), window.location.origin).toString(); } -function isModifiedMousePress(event?: ModifiedMouseEvent) { +function getPrimaryButtonMouseEvent(event?: ModifiedMouseEvent): ModifiedMouseEventSource | undefined { const mouseEvent = event?.nativeEvent && typeof event.nativeEvent === 'object' ? (event.nativeEvent as ModifiedMouseEventSource) : event; if (!mouseEvent || 'key' in mouseEvent) { - return false; + return undefined; } const isPrimaryButton = mouseEvent.button === undefined || mouseEvent.button === 0; - return isPrimaryButton && (!!mouseEvent.metaKey || !!mouseEvent.ctrlKey); + return isPrimaryButton ? mouseEvent : undefined; +} + +function isModifiedMousePress(event?: ModifiedMouseEvent) { + const mouseEvent = getPrimaryButtonMouseEvent(event); + return !!mouseEvent?.metaKey || !!mouseEvent?.ctrlKey; +} + +/** Browsers open a link in a new window on a Shift click, so a real link leaves that click to the browser too. */ +function isNewTabOrWindowMousePress(event?: ModifiedMouseEvent) { + return isModifiedMousePress(event) || !!getPrimaryButtonMouseEvent(event)?.shiftKey; } function openInternalRouteInNewTab(route: Route, event?: ModifiedMouseEvent) { @@ -28,6 +40,6 @@ function openInternalRouteInNewTab(route: Route, event?: ModifiedMouseEvent) { return true; } -export {isModifiedMousePress}; +export {isModifiedMousePress, isNewTabOrWindowMousePress}; export type {ModifiedMouseEvent}; export default openInternalRouteInNewTab; diff --git a/src/libs/Navigation/helpers/openInternalRouteInNewTab/types.ts b/src/libs/Navigation/helpers/openInternalRouteInNewTab/types.ts index f1c30410b64e..01778378bf3a 100644 --- a/src/libs/Navigation/helpers/openInternalRouteInNewTab/types.ts +++ b/src/libs/Navigation/helpers/openInternalRouteInNewTab/types.ts @@ -3,11 +3,12 @@ type ModifiedMouseEvent = { stopPropagation?: () => void; metaKey?: boolean; ctrlKey?: boolean; + shiftKey?: boolean; button?: number; key?: string; nativeEvent?: unknown; }; -type ModifiedMouseEventSource = Pick; +type ModifiedMouseEventSource = Pick; export type {ModifiedMouseEvent, ModifiedMouseEventSource}; diff --git a/src/pages/inbox/sidebar/NavigationTabBarAvatar.tsx b/src/pages/inbox/sidebar/NavigationTabBarAvatar.tsx index 063834e70ae6..456a9a4c721e 100644 --- a/src/pages/inbox/sidebar/NavigationTabBarAvatar.tsx +++ b/src/pages/inbox/sidebar/NavigationTabBarAvatar.tsx @@ -34,7 +34,8 @@ function NavigationTabBarAvatar({onPress, isSelected = false, style}: Navigation const {status} = useAccountTabIndicatorStatus(); const accountAccessibilityState = {selected: isSelected}; - const accountLinkRoute = useSignedInLinkRoute(ROUTES.SETTINGS); + const getSignedInLinkRoute = useSignedInLinkRoute(); + const accountLinkRoute = getSignedInLinkRoute(ROUTES.SETTINGS); return ( jest.requi const TEST_ID = 'link-pressable'; -function renderLinkPressable(onPress: () => void, isDisabled = false) { +function renderLinkPressable(onPress: () => void, isDisabled = false, isInteractive = true) { render( { expect(onPress).not.toHaveBeenCalled(); }); + it('leaves a Shift click to the browser so the route opens in a new window', () => { + // Given a pressable linking to the settings route + const onPress = jest.fn(); + const preventDefault = jest.fn(); + renderLinkPressable(onPress); + + // When it is clicked with the Shift key held + fireEvent.press(screen.getByTestId(TEST_ID), {nativeEvent: {button: 0, shiftKey: true}, preventDefault}); + + // Then the current tab does not navigate and the browser keeps its default new window behavior + expect(preventDefault).not.toHaveBeenCalled(); + expect(onPress).not.toHaveBeenCalled(); + }); + + it('leaves Enter to the browser so Cmd or Ctrl reaches the click it fires', () => { + // Given a pressable with the link role linking to the settings route + const onPress = jest.fn(); + const preventDefault = jest.fn(); + renderLinkPressable(onPress); + + // When Enter is pressed on it + fireEvent(screen.getByTestId(TEST_ID), 'keyDown', {key: CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey, nativeEvent: {}, preventDefault}); + + // Then the key press does not navigate on its own, so the browser's click decides between this tab and a new one + expect(preventDefault).not.toHaveBeenCalled(); + expect(onPress).not.toHaveBeenCalled(); + }); + + it('renders no href when not interactive', () => { + // Given a pressable linking to the settings route that ignores presses + // When it renders + renderLinkPressable(jest.fn(), false, false); + + // Then there is no href, so a Cmd click cannot open a route a plain click would not + expect(screen.getByTestId(TEST_ID).props.href).toBeUndefined(); + }); + it('renders no href when disabled', () => { // Given a disabled pressable linking to the settings route // When it renders diff --git a/tests/unit/useSignedInLinkRouteTest.ts b/tests/unit/useSignedInLinkRouteTest.ts index 69add62d947a..acb6dc874966 100644 --- a/tests/unit/useSignedInLinkRouteTest.ts +++ b/tests/unit/useSignedInLinkRouteTest.ts @@ -26,10 +26,10 @@ describe('useSignedInLinkRoute', () => { await waitForBatchedUpdates(); // When the hook resolves the Account tab link - const {result} = renderHook(() => useSignedInLinkRoute(ROUTES.SETTINGS)); + const {result} = renderHook(() => useSignedInLinkRoute()); // Then the tab can be opened in a new browser tab - expect(result.current).toBe(ROUTES.SETTINGS); + expect(result.current(ROUTES.SETTINGS)).toBe(ROUTES.SETTINGS); }); it('returns no route for an anonymous user', async () => { @@ -38,9 +38,9 @@ describe('useSignedInLinkRoute', () => { await waitForBatchedUpdates(); // When the hook resolves the Account tab link - const {result} = renderHook(() => useSignedInLinkRoute(ROUTES.SETTINGS)); + const {result} = renderHook(() => useSignedInLinkRoute()); // Then there is no link, so a Cmd click cannot open the tab without the sign in prompt - expect(result.current).toBeUndefined(); + expect(result.current(ROUTES.SETTINGS)).toBeUndefined(); }); }); From 9cb26a55149f40a3d0d101b71be81b11f0204737 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Mon, 16 Nov 2026 20:41:12 +0530 Subject: [PATCH 5/6] Keep the bold tab label copy out of the link text on web The hidden bold copy that reserves a tab label's width was part of the link's text content, so dragging a tab showed the title twice. On web it is now drawn by a CSS pseudo-element, which reserves the same width without adding text. Signed-off-by: krishna2323 --- src/CONST/index.ts | 1 + .../NavigationTabBar/TabBarLabel.tsx | 10 ++++---- .../index.native.tsx | 19 +++++++++++++++ .../TabBarLabelBoldPlaceholder/index.tsx | 23 +++++++++++++++++++ .../TabBarLabelBoldPlaceholder/types.ts | 9 ++++++++ web/index.html | 4 ++++ 6 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/index.native.tsx create mode 100644 src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/index.tsx create mode 100644 src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/types.ts diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 563410e2432a..35dad5fbeda4 100644 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -7468,6 +7468,7 @@ const CONST = { // that should be removed from the copied contents in the getHTMLOfSelection() method SELECTION_SCRAPER_HIDDEN_ELEMENT: 'selection-scrapper-hidden-element', INNER_BOX_SHADOW_ELEMENT: 'inner-box-shadow-element', + TAB_BAR_LABEL_BOLD_PLACEHOLDER: 'tab-bar-label-bold-placeholder', COPYABLE_TEXT_ELEMENT: 'copyable-text', COPYABLE_ROW_ELEMENT: 'copyable-row', COPYABLE_ROW_CONTINUATION_ELEMENT: 'copyable-row-continuation', diff --git a/src/components/Navigation/NavigationTabBar/TabBarLabel.tsx b/src/components/Navigation/NavigationTabBar/TabBarLabel.tsx index 5dfcab506d56..3267dbbb3eb5 100644 --- a/src/components/Navigation/NavigationTabBar/TabBarLabel.tsx +++ b/src/components/Navigation/NavigationTabBar/TabBarLabel.tsx @@ -7,6 +7,8 @@ import type {StyleProp, ViewStyle} from 'react-native'; import React from 'react'; import {View} from 'react-native'; +import TabBarLabelBoldPlaceholder from './TabBarLabelBoldPlaceholder'; + type TabBarLabelProps = { label: string; isSelected: boolean; @@ -27,13 +29,11 @@ function TabBarLabel({label, isSelected, numberOfLines, style}: TabBarLabelProps > {label} - - {label} - + /> ); } diff --git a/src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/index.native.tsx b/src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/index.native.tsx new file mode 100644 index 000000000000..3bb5b4eb79eb --- /dev/null +++ b/src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/index.native.tsx @@ -0,0 +1,19 @@ +import Text from '@components/Text'; + +import React from 'react'; + +import type TabBarLabelBoldPlaceholderProps from './types'; + +function TabBarLabelBoldPlaceholder({label, numberOfLines, style}: TabBarLabelBoldPlaceholderProps) { + return ( + + {label} + + ); +} + +export default TabBarLabelBoldPlaceholder; diff --git a/src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/index.tsx b/src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/index.tsx new file mode 100644 index 000000000000..6e757025cea2 --- /dev/null +++ b/src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/index.tsx @@ -0,0 +1,23 @@ +import Text from '@components/Text'; + +import CONST from '@src/CONST'; + +import React from 'react'; + +import type TabBarLabelBoldPlaceholderProps from './types'; + +/** The label is drawn by a CSS pseudo-element, so it stays out of the text a browser takes when the tab link is dragged or copied. */ +function TabBarLabelBoldPlaceholder({label, numberOfLines, style}: TabBarLabelBoldPlaceholderProps) { + return ( + + {null} + + ); +} + +export default TabBarLabelBoldPlaceholder; diff --git a/src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/types.ts b/src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/types.ts new file mode 100644 index 000000000000..a9d5dd25ee01 --- /dev/null +++ b/src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/types.ts @@ -0,0 +1,9 @@ +import type {StyleProp, TextStyle} from 'react-native'; + +type TabBarLabelBoldPlaceholderProps = { + label: string; + numberOfLines: number; + style: StyleProp; +}; + +export default TabBarLabelBoldPlaceholderProps; diff --git a/web/index.html b/web/index.html index a7090861da54..ebbea2669a84 100644 --- a/web/index.html +++ b/web/index.html @@ -87,6 +87,10 @@ pointer-events: none; z-index: 1000; } + /* Reserve the width of a tab's bold label without putting the label in the link text that browsers drag and copy */ + [data-tab-bar-label-bold-placeholder]::after { + content: attr(data-tab-bar-label-bold-placeholder); + } :focus[data-focusvisible-polyfill]:not([data-programmatic-focus="true"]) { outline: 0; box-shadow: inset 0px 0px 0px 1px #5AB0FF; From 4adc54f27d2dceaa8f588c45c4aaef3f4117198d Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Wed, 18 Nov 2026 04:57:42 +0530 Subject: [PATCH 6/6] Document the tab bar label bold placeholder props Signed-off-by: krishna2323 --- .../NavigationTabBar/TabBarLabelBoldPlaceholder/types.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/types.ts b/src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/types.ts index a9d5dd25ee01..cb738b5d77bb 100644 --- a/src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/types.ts +++ b/src/components/Navigation/NavigationTabBar/TabBarLabelBoldPlaceholder/types.ts @@ -1,8 +1,13 @@ import type {StyleProp, TextStyle} from 'react-native'; type TabBarLabelBoldPlaceholderProps = { + /** Tab label whose bold width is reserved. On web it goes in a data attribute instead of the text, so it stays out of the link text */ label: string; + + /** Number of lines the visible label is limited to */ numberOfLines: number; + + /** Style of the visible label in bold, so the placeholder takes the same width */ style: StyleProp; };