π€― 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(desktop): remove close affordances from a lone tab (#21749)
AmAzing-ed67a3a33500
diff --git a/src/features/Electron/titlebar/TabBar/TabItem.tsx b/src/features/Electron/titlebar/TabBar/TabItem.tsxindex 37a1809e469..48dc185a1b2 100644--- a/src/features/Electron/titlebar/TabBar/TabItem.tsx+++ b/src/features/Electron/titlebar/TabBar/TabItem.tsx@@ -18,6 +18,7 @@ import { useTabRunning } from './hooks/useTabRunning';import { useTabUnread } from './hooks/useTabUnread';import { TAB_SPRING } from './motion';import { useStyles } from './styles';+import { isTabClosable } from './tabClose';import { buildTabContextMenuItems } from './tabContextMenu';import { rubberBand } from './tabDrag';import { resolveTabInset, type TabTier } from './tabLayout';@@ -106,8 +107,9 @@ const TabItem = memo<TabItemProps>(// Which tiers actually show the button is settled in CSS so that it can fade rather// than unmount. Staying mounted below the compact tier would otherwise leave an// invisible button in the focus order, so those tiers are made inert rather than- // merely transparent.- const closeInert = tier !== 'full' && tier !== 'compact';+ // merely transparent. A lone tab is not closable at all (see tabClose).+ const closable = isTabClosable(totalCount);+ const closeInert = !closable || (tier !== 'full' && tier !== 'compact');const isDragging = !!drag;@@ -210,9 +212,9 @@ const TabItem = memo<TabItemProps>((e: React.MouseEvent) => {if (e.button !== 1) return;e.preventDefault();- onClose(id);+ if (closable) onClose(id);},- [onClose, id],+ [closable, onClose, id],);const contextMenuItems = useCallback(@@ -280,6 +282,7 @@ const TabItem = memo<TabItemProps>(const face = (<m.divdata-active={isActive ? 'true' : undefined}+ data-closable={closable ? 'true' : undefined}data-tier={tier}role="button"tabIndex={0}diff --git a/src/features/Electron/titlebar/TabBar/styles.ts b/src/features/Electron/titlebar/TabBar/styles.tsindex 3ad96957e83..775079f31e6 100644--- a/src/features/Electron/titlebar/TabBar/styles.ts+++ b/src/features/Electron/titlebar/TabBar/styles.ts@@ -134,16 +134,19 @@ export const useStyles = createStaticStyles(({ css, cssVar }) => ({too. The button stays mounted at every tier and fades; unmounting it made it vanishmid-pin.+ A lone tab is not closable, so the rule is gated on data-closable as well; the+ button then stays faded and inert, and the title keeps its full width.+:has() carries the keyboard path β the button is focusable at these tiers, sowithout it a tabbing user would land on something invisible.Reservation is 20px button + 3px inset - the tab's own 6px end padding. Marginrather than padding: the mask applies to the padding box, so padding would put thegradient inside the reservation instead of at the text's edge. */- &[data-tier='full']:hover,- &[data-tier='compact']:hover,- &[data-tier='full']:has([data-tab-close]:focus-visible),- &[data-tier='compact']:has([data-tab-close]:focus-visible) {+ &[data-closable][data-tier='full']:hover,+ &[data-closable][data-tier='compact']:hover,+ &[data-closable][data-tier='full']:has([data-tab-close]:focus-visible),+ &[data-closable][data-tier='compact']:has([data-tab-close]:focus-visible) {[data-tab-close] {pointer-events: auto;opacity: 1;diff --git a/src/features/Electron/titlebar/TabBar/tabClose.ts b/src/features/Electron/titlebar/TabBar/tabClose.tsnew file mode 100644index 00000000000..58a2b5bc0bf--- /dev/null+++ b/src/features/Electron/titlebar/TabBar/tabClose.ts@@ -0,0 +1,4 @@+// A lone tab offers no close at all β button, middle-click or context menu. Closing it+// only swaps in a fresh home tab, so each would read as a way out that does not exist.+// The window-close shortcut keeps its own rules (see resolveCloseShortcut).+export const isTabClosable = (totalCount: number): boolean => totalCount > 1;diff --git a/src/features/Electron/titlebar/TabBar/tabContextMenu.test.ts b/src/features/Electron/titlebar/TabBar/tabContextMenu.test.tsindex 8bb4c9867e7..79e5814c9ff 100644--- a/src/features/Electron/titlebar/TabBar/tabContextMenu.test.ts+++ b/src/features/Electron/titlebar/TabBar/tabContextMenu.test.ts@@ -43,13 +43,10 @@ describe('tab context menu ownership', () => {});describe('close entries', () => {- it('lets a lone tab close itself while the bulk closes have nothing to reach', () => {- const items = build(0, 1);+ it('leaves the whole close group out for a lone tab', () => {+ const keys = build(0, 1).map((item) => (item && 'key' in item ? item.key : item?.type));- expect(isDisabled(items, 'closeCurrentTab')).toBe(false);- expect(isDisabled(items, 'closeOtherTabs')).toBe(true);- expect(isDisabled(items, 'closeLeftTabs')).toBe(true);- expect(isDisabled(items, 'closeRightTabs')).toBe(true);+ expect(keys).toEqual(['togglePin', 'openInSplitView']);});});diff --git a/src/features/Electron/titlebar/TabBar/tabContextMenu.ts b/src/features/Electron/titlebar/TabBar/tabContextMenu.tsindex 77aada65019..073156e049b 100644--- a/src/features/Electron/titlebar/TabBar/tabContextMenu.ts+++ b/src/features/Electron/titlebar/TabBar/tabContextMenu.ts@@ -1,5 +1,7 @@import type { DropdownItem } from '@lobehub/ui';+import { isTabClosable } from './tabClose';+type TabContextMenuLabelKey =| 'tab.closeCurrentTab'| 'tab.closeLeftTabs'@@ -52,7 +54,7 @@ export const buildTabContextMenuItems = ({const closableRight = Math.max(0, totalCount - Math.max(index + 1, pinnedCount));const closableOthers = totalCount - pinnedCount - (pinned ? 0 : 1);- return [+ const tabEntries: DropdownItem[] = [{key: 'togglePin',label: pinned ? t('tab.unpin') : t('tab.pin'),@@ -65,6 +67,14 @@ export const buildTabContextMenuItems = ({onClick: () => (inSplitView ? onCloseSplitView() : onOpenInSplitView(id)),}: null,+ ];++ // A lone tab has nothing to close (see tabClose), so the whole close group is left out+ // rather than shown disabled.+ if (!isTabClosable(totalCount)) return tabEntries;++ return [+ ...tabEntries,{ type: 'divider' },{key: 'closeCurrentTab',