Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

💄 style: support Cmd+Click to open sidebar nav in new tab (#12574)

YuTengjingc068363fac92
diff --git a/packages/builtin-tool-web-browsing/src/client/Inspector/CrawlMultiPages/index.tsx b/packages/builtin-tool-web-browsing/src/client/Inspector/CrawlMultiPages/index.tsx
index a0bf00944b6..ff0c36b1bfd 100644
--- a/packages/builtin-tool-web-browsing/src/client/Inspector/CrawlMultiPages/index.tsx
+++ b/packages/builtin-tool-web-browsing/src/client/Inspector/CrawlMultiPages/index.tsx
@@ -41,7 +41,9 @@ export const CrawlMultiPagesInspector = memo<BuiltinInspectorProps<CrawlMultiPag
<div
className={cx(inspectorTextStyles.root, isArgumentsStreaming && shinyTextStyles.shinyText)}
>
- <span>{t('builtins.lobe-web-browsing.apiName.crawlMultiPages')}: </span>
+ <span>
+ {t('builtins.lobe-web-browsing.apiName.crawlMultiPages')}:{'\u00A0'}
+ </span>
{displayText && <span className={highlightTextStyles.gold}>{displayText}</span>}
</div>
);
diff --git a/packages/builtin-tool-web-browsing/src/client/Inspector/CrawlSinglePage/index.tsx b/packages/builtin-tool-web-browsing/src/client/Inspector/CrawlSinglePage/index.tsx
index fa050293f7a..3c165551811 100644
--- a/packages/builtin-tool-web-browsing/src/client/Inspector/CrawlSinglePage/index.tsx
+++ b/packages/builtin-tool-web-browsing/src/client/Inspector/CrawlSinglePage/index.tsx
@@ -29,7 +29,9 @@ export const CrawlSinglePageInspector = memo<BuiltinInspectorProps<CrawlSinglePa
<div
className={cx(inspectorTextStyles.root, isArgumentsStreaming && shinyTextStyles.shinyText)}
>
- <span>{t('builtins.lobe-web-browsing.apiName.crawlSinglePage')}: </span>
+ <span>
+ {t('builtins.lobe-web-browsing.apiName.crawlSinglePage')}:{'\u00A0'}
+ </span>
{url && <span className={highlightTextStyles.gold}>{url}</span>}
</div>
);
diff --git a/packages/builtin-tool-web-browsing/src/client/Inspector/Search/index.tsx b/packages/builtin-tool-web-browsing/src/client/Inspector/Search/index.tsx
index 54ce1877a62..093b48b900f 100644
--- a/packages/builtin-tool-web-browsing/src/client/Inspector/Search/index.tsx
+++ b/packages/builtin-tool-web-browsing/src/client/Inspector/Search/index.tsx
@@ -31,7 +31,9 @@ export const SearchInspector = memo<BuiltinInspectorProps<SearchQuery, UniformSe
(isArgumentsStreaming || isLoading) && shinyTextStyles.shinyText,
)}
>
- <span>{t('builtins.lobe-web-browsing.apiName.search')}: </span>
+ <span>
+ {t('builtins.lobe-web-browsing.apiName.search')}:{'\u00A0'}
+ </span>
{query && <span className={highlightTextStyles.primary}>{query}</span>}
{!isLoading &&
!isArgumentsStreaming &&
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx
index f3a33d6a047..24ccee23bc3 100644
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx
@@ -100,6 +100,10 @@ const Tool = memo<GroupToolProps>(
if (isAlwaysExpand && expand === false) {
return;
}
+ // When collapsing, also turn off debug mode so the accordion can actually collapse
+ if (expand === false) {
+ setShowDebug(false);
+ }
setShowToolRender(!!expand);
};
diff --git a/src/features/NavPanel/SideBarHeaderLayout.tsx b/src/features/NavPanel/SideBarHeaderLayout.tsx
index 889ed4a29b3..fabed7e3381 100644
--- a/src/features/NavPanel/SideBarHeaderLayout.tsx
+++ b/src/features/NavPanel/SideBarHeaderLayout.tsx
@@ -11,6 +11,7 @@ import { flushSync } from 'react-dom';
import { useNavigate } from 'react-router-dom';
import { isDesktop } from '@/const/version';
+import { isModifierClick } from '@/utils/navigation';
import BackButton from './components/BackButton';
import ToggleLeftPanelButton from './ToggleLeftPanelButton';
@@ -103,6 +104,7 @@ const SideBarHeaderLayout = memo<SideBarHeaderLayoutProps>(
].map((item) => ({
...item,
onClick: (event) => {
+ if (isModifierClick(event)) return;
const href = item.href;
if (href) {
event.preventDefault();
diff --git a/src/features/NavPanel/components/BackNav.tsx b/src/features/NavPanel/components/BackNav.tsx
index e25e9c2272b..15bfeaf98be 100644
--- a/src/features/NavPanel/components/BackNav.tsx
+++ b/src/features/NavPanel/components/BackNav.tsx
@@ -1,12 +1,13 @@
import { ActionIcon, Button, Flexbox } from '@lobehub/ui';
import { createStaticStyles } from 'antd-style';
import { ChevronLeftIcon } from 'lucide-react';
-import { type PropsWithChildren } from 'react';
+import { type MouseEvent, type PropsWithChildren, type ReactNode, useCallback } from 'react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
-import { useNavigate } from 'react-router-dom';
+import { Link, useNavigate } from 'react-router-dom';
import { DESKTOP_HEADER_ICON_SIZE } from '@/const/layoutTokens';
+import { isModifierClick } from '@/utils/navigation';
import ToggleLeftPanelButton from '../ToggleLeftPanelButton';
@@ -23,33 +24,41 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
`,
}));
-const BackNav = memo<PropsWithChildren>(({ children }) => {
+const BackLink = ({ children }: { children: ReactNode }) => {
const navigate = useNavigate();
+ const handleClick = useCallback(
+ (e: MouseEvent) => {
+ if (isModifierClick(e)) return;
+ e.preventDefault();
+ navigate('/');
+ },
+ [navigate],
+ );
+
+ return (
+ <Link to="/" onClick={handleClick}>
+ {children}
+ </Link>
+ );
+};
+
+const BackNav = memo<PropsWithChildren>(({ children }) => {
const { t } = useTranslation('common');
- let leftContent;
- if (!children) {
- leftContent = (
- <Button
- className={styles.button}
- icon={ChevronLeftIcon}
- type={'text'}
- onClick={() => navigate('/')}
- >
+ const leftContent = children ? (
+ <Flexbox horizontal align={'center'} gap={4}>
+ <BackLink>
+ <ActionIcon icon={ChevronLeftIcon} size={DESKTOP_HEADER_ICON_SIZE} />
+ </BackLink>
+ {children}
+ </Flexbox>
+ ) : (
+ <BackLink>
+ <Button className={styles.button} icon={ChevronLeftIcon} type={'text'}>
{t('back')}
</Button>
- );
- } else {
- leftContent = (
- <Flexbox horizontal align={'center'} gap={4}>
- <ActionIcon
- icon={ChevronLeftIcon}
- size={DESKTOP_HEADER_ICON_SIZE}
- onClick={() => navigate('/')}
- />
- {children}
- </Flexbox>
- );
- }
+ </BackLink>
+ );
+
return (
<Flexbox horizontal align={'center'} gap={4} justify={'space-between'} padding={8}>
{leftContent}
diff --git a/src/features/NavPanel/components/NavItem.tsx b/src/features/NavPanel/components/NavItem.tsx
index 8db7a2dc2d1..878e8e2dbb5 100644
--- a/src/features/NavPanel/components/NavItem.tsx
+++ b/src/features/NavPanel/components/NavItem.tsx
@@ -7,6 +7,7 @@ import { type ReactNode } from 'react';
import { memo } from 'react';
import NeuralNetworkLoading from '@/components/NeuralNetworkLoading';
+import { isModifierClick } from '@/utils/navigation';
const ACTION_CLASS_NAME = 'nav-item-actions';
@@ -104,7 +105,7 @@ const NavItem = memo<NavItemProps>(
if (disabled || loading) return;
// Prevent default link behavior for normal clicks (let onClick handle it)
// But allow cmd+click to open in new tab
- if (href && !e.metaKey && !e.ctrlKey) {
+ if (href && !isModifierClick(e)) {
e.preventDefault();
}
onClick?.(e);
diff --git a/src/routes/(main)/community/_layout/Sidebar/Header/Nav.tsx b/src/routes/(main)/community/_layout/Sidebar/Header/Nav.tsx
index 6b5b0b12ad7..0e5f4fe00d0 100644
--- a/src/routes/(main)/community/_layout/Sidebar/Header/Nav.tsx
+++ b/src/routes/(main)/community/_layout/Sidebar/Header/Nav.tsx
@@ -11,6 +11,7 @@ import { type NavItemProps } from '@/features/NavPanel/components/NavItem';
import NavItem from '@/features/NavPanel/components/NavItem';
import { usePathname } from '@/libs/router/navigation';
import { DiscoverTab } from '@/types/discover';
+import { isModifierClick } from '@/utils/navigation';
interface Item {
icon: NavItemProps['icon'];
@@ -86,6 +87,7 @@ const Nav = memo(() => {
key={item.key}
to={item.url}
onClick={(e) => {
+ if (isModifierClick(e)) return;
e.preventDefault();
item?.onClick?.();
if (item.url) {
diff --git a/src/routes/(main)/eval/_layout/Sidebar/Body/BenchmarkList.tsx b/src/routes/(main)/eval/_layout/Sidebar/Body/BenchmarkList.tsx
index c24349cbea9..c95de4013dc 100644
--- a/src/routes/(main)/eval/_layout/Sidebar/Body/BenchmarkList.tsx
+++ b/src/routes/(main)/eval/_layout/Sidebar/Body/BenchmarkList.tsx
@@ -21,6 +21,7 @@ import { Link, useNavigate } from 'react-router-dom';
import NavItem from '@/features/NavPanel/components/NavItem';
import SkeletonList from '@/features/NavPanel/components/SkeletonList';
import { useEvalStore } from '@/store/eval';
+import { isModifierClick } from '@/utils/navigation';
const SYSTEM_ICONS = [
LoaderPinwheel,
@@ -79,6 +80,7 @@ const BenchmarkList = memo<BenchmarkListProps>(({ activeKey, itemKey }) => {
key={b.id}
to={`/eval/bench/${b.id}`}
onClick={(e) => {
+ if (isModifierClick(e)) return;
e.preventDefault();
navigate(`/eval/bench/${b.id}`);
}}
diff --git a/src/routes/(main)/home/_layout/Body/BottomMenu/index.tsx b/src/routes/(main)/home/_layout/Body/BottomMenu/index.tsx
index d5367acd3ba..2d07dc1bc6c 100644
--- a/src/routes/(main)/home/_layout/Body/BottomMenu/index.tsx
+++ b/src/routes/(main)/home/_layout/Body/BottomMenu/index.tsx
@@ -7,6 +7,7 @@ import { getRouteById } from '@/config/routes';
import NavItem from '@/features/NavPanel/components/NavItem';
import { useActiveTabKey } from '@/hooks/useActiveTabKey';
import { SidebarTabKey } from '@/store/global/initialState';
+import { isModifierClick } from '@/utils/navigation';
interface Item {
icon: any;
@@ -59,6 +60,7 @@ const BottomMenu = memo(() => {
key={item.key}
to={item.url}
onClick={(e) => {
+ if (isModifierClick(e)) return;
e.preventDefault();
navigate(item.url);
}}
diff --git a/src/routes/(main)/home/_layout/Header/components/Nav.tsx b/src/routes/(main)/home/_layout/Header/components/Nav.tsx
index b8a01c668b5..830f3855c0d 100644
--- a/src/routes/(main)/home/_layout/Header/components/Nav.tsx
+++ b/src/routes/(main)/home/_layout/Header/components/Nav.tsx
@@ -17,6 +17,7 @@ import {
serverConfigSelectors,
useServerConfigStore,
} from '@/store/serverConfig';
+import { isModifierClick } from '@/utils/navigation';
interface Item {
hidden?: boolean | undefined;
@@ -111,6 +112,7 @@ const Nav = memo(() => {
key={item.key}
to={item.url}
onClick={(e) => {
+ if (isModifierClick(e)) return;
e.preventDefault();
item?.onClick?.();
if (item.url) {
diff --git a/src/routes/(main)/memory/_layout/Sidebar/Header/Nav.tsx b/src/routes/(main)/memory/_layout/Sidebar/Header/Nav.tsx
index 881d6e63425..1100b520e69 100644
--- a/src/routes/(main)/memory/_layout/Sidebar/Header/Nav.tsx
+++ b/src/routes/(main)/memory/_layout/Sidebar/Header/Nav.tsx
@@ -18,6 +18,7 @@ import { type NavItemProps } from '@/features/NavPanel/components/NavItem';
import NavItem from '@/features/NavPanel/components/NavItem';
import { usePathname } from '@/libs/router/navigation';
import { useGlobalStore } from '@/store/global';
+import { isModifierClick } from '@/utils/navigation';
interface Item {
icon: NavItemProps['icon'];
@@ -117,6 +118,7 @@ const Nav = memo(() => {
key={item.key}
to={item.url}
onClick={(e) => {
+ if (isModifierClick(e)) return;
e.preventDefault();
item?.onClick?.();
if (item.url) {
diff --git a/src/routes/(main)/settings/_layout/Body/index.tsx b/src/routes/(main)/settings/_layout/Body/index.tsx
index be5c38e4aab..be503e5ad1e 100644
--- a/src/routes/(main)/settings/_layout/Body/index.tsx
+++ b/src/routes/(main)/settings/_layout/Body/index.tsx
@@ -2,10 +2,11 @@
import { Accordion, AccordionItem, Flexbox, Text } from '@lobehub/ui';
import { memo, useMemo } from 'react';
-import { useLocation, useNavigate } from 'react-router-dom';
+import { Link, useLocation, useNavigate } from 'react-router-dom';
import NavItem from '@/features/NavPanel/components/NavItem';
import { SettingsTabs } from '@/store/global/initialState';
+import { isModifierClick } from '@/utils/navigation';
import { SettingsGroupKey, useCategory } from '../../hooks/useCategory';
@@ -24,12 +25,8 @@ const Body = memo(() => {
return SettingsTabs.Profile;
}, [location.pathname]);
- const handleTabClick = (tab: SettingsTabs) => {
- if (tab === SettingsTabs.Provider) {
- navigate('/settings/provider/all');
- } else {
- navigate(`/settings/${tab}`);
- }
+ const getTabUrl = (tab: SettingsTabs) => {
+ return tab === SettingsTabs.Provider ? '/settings/provider/all' : `/settings/${tab}`;
};
return (
@@ -57,15 +54,22 @@ const Body = memo(() => {
}
>
<Flexbox gap={1} paddingBlock={1}>
- {group.items.map((item) => (
- <NavItem
- active={activeTab === item.key}
- icon={item.icon}
- key={item.key}
- title={item.label}
- onClick={() => handleTabClick(item.key)}
- />
- ))}
+ {group.items.map((item) => {
+ const url = getTabUrl(item.key);
+ return (
+ <Link
+ key={item.key}
+ to={url}
+ onClick={(e) => {
+ if (isModifierClick(e)) return;
+ e.preventDefault();
+ navigate(url);
+ }}
+ >
+ <NavItem active={activeTab === item.key} icon={item.icon} title={item.label} />
+ </Link>
+ );
+ })}
</Flexbox>
</AccordionItem>
))}
diff --git a/src/utils/navigation.ts b/src/utils/navigation.ts
new file mode 100644
index 00000000000..b6cdf877c98
--- /dev/null
+++ b/src/utils/navigation.ts
@@ -0,0 +1,11 @@
+import { isDesktop } from '@/const/version';
+
+/**
+ * Check if user is performing a modifier click (Cmd+Click on Mac, Ctrl+Click on other OS)
+ * to open link in new tab. Always returns false on desktop (Electron) since
+ * there's no browser tab concept.
+ */
+export const isModifierClick = (e: { ctrlKey: boolean; metaKey: boolean }): boolean => {
+ if (isDesktop) return false;
+ return e.metaKey || e.ctrlKey;
+};