π€― 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
π style(working-panel): show tab close button only on the selected tab (#21879)
AmAzing-fb3de112bb6a
diff --git a/src/features/Conversation/WorkingSidebar/WorkspaceTab.tsx b/src/features/Conversation/WorkingSidebar/WorkspaceTab.tsxindex 42f6be1b7d9..d3b2b6841cd 100644--- a/src/features/Conversation/WorkingSidebar/WorkspaceTab.tsx+++ b/src/features/Conversation/WorkingSidebar/WorkspaceTab.tsx@@ -1,38 +1,68 @@-import { type ContextMenuItem, ContextMenuTrigger, Icon, type IconProps } from '@lobehub/ui';-import { createStaticStyles } from '@lobehub/ui';+import {+ type ContextMenuItem,+ ContextMenuTrigger,+ createStaticStyles,+ Icon,+ type IconProps,+ keyframes,+} from '@lobehub/ui';import { PinIcon, XIcon } from 'lucide-react';-import { memo, type ReactNode } from 'react';+import { memo, type MouseEvent, type ReactNode } from 'react';++/**+ * Room the trailing close button / pin badge needs at the tab's end. Pinned tabs+ * always reserve it for the badge; the active tab instead overlays its close+ * button there and truncates the label under it, browser-style, so selecting a+ * tab never changes its width and unselected tabs carry no empty gap.+ */+const TRAILING_SLOT = 24;+const TAB_PADDING = 8;++const fadeIn = keyframes`+ from {+ opacity: 0;+ }++ to {+ opacity: 1;+ }+`;const styles = createStaticStyles(({ css, cssVar }) => ({close: css`- pointer-events: none;cursor: pointer;position: absolute;inset-block-start: 50%;- inset-inline-start: 7px;+ inset-inline-end: 4px;transform: translateY(-50%);display: grid;place-items: center;- width: 20px;- height: 20px;+ width: 16px;+ height: 16px;padding: 0;border: none;border-radius: 4px;color: ${cssVar.colorTextTertiary};- opacity: 0;background: transparent;- transition: opacity 0.15s;+ transition:+ color 0.15s,+ background 0.15s;+ animation: ${fadeIn} 0.15s ease-out;&:hover {color: ${cssVar.colorText};background: ${cssVar.colorFillSecondary};}++ @media (prefers-reduced-motion: reduce) {+ animation: none;+ }`,container: css`position: relative;@@ -48,31 +78,6 @@ const styles = createStaticStyles(({ css, cssVar }) => ({&:hover {background: ${cssVar.colorFillSecondary};}-- /* the close button takes over the leading icon's slot instead of reserving- its own trailing space; while hidden it must not swallow taps on the icon */- &:hover [data-tab-close],- & [data-tab-close]:focus-visible {- pointer-events: auto;- opacity: 1;- }-- /* keyboard focus on the select button keeps the icon, so the visible glyph- always matches the action Enter/Space would run */- &:hover [data-tab-icon],- &:has([data-tab-close]:focus-visible) [data-tab-icon] {- opacity: 0;- }-- /* keyboard focus on the select button outranks hover */- &:has([data-tab-key]:focus-visible) [data-tab-icon] {- opacity: 1;- }-- &:has([data-tab-key]:focus-visible) [data-tab-close] {- pointer-events: none;- opacity: 0;- }`,containerActive: css`background: ${cssVar.colorFillTertiary};@@ -82,7 +87,7 @@ const styles = createStaticStyles(({ css, cssVar }) => ({position: absolute;inset-block-start: 50%;- inset-inline-end: 8px;+ inset-inline-end: 6px;transform: translateY(-50%);display: grid;@@ -92,18 +97,49 @@ const styles = createStaticStyles(({ css, cssVar }) => ({`,icon: css`display: flex;- transition: opacity 0.15s;+ flex-shrink: 0;`,label: css`+ /* a hidden copy of the label (data-label) shares the grid cell with the+ visible text: the cell keeps the full label's width, and only the visible+ copy shrinks under the close button */+ display: grid;++ &[data-label]::before {+ content: attr(data-label);++ overflow: hidden;+ grid-area: 1 / 1;++ min-width: 24px;+ max-width: 160px;++ visibility: hidden;+ }++ /* the visible copy contributes no width of its own, so the cell is sized by+ the hidden one; non-string labels have no hidden copy and size normally */+ &[data-label] > * {+ contain: inline-size;+ }+ `,+ labelText: css`overflow: hidden;+ grid-area: 1 / 1;++ min-width: 0;max-width: 160px;+text-overflow: ellipsis;`,+ labelTextBehindClose: css`+ padding-inline-end: ${TRAILING_SLOT - TAB_PADDING}px;+ `,tab: css`cursor: pointer;padding-block: 4px;- padding-inline: 10px;+ padding-inline: ${TAB_PADDING}px;border: none;border-radius: 6px;@@ -126,7 +162,7 @@ const styles = createStaticStyles(({ css, cssVar }) => ({}`,tabPinned: css`- padding-inline-end: 30px;+ padding-inline-end: ${TRAILING_SLOT}px;`,trigger: css`display: flex;@@ -163,30 +199,57 @@ const WorkspaceTab = memo<WorkspaceTabProps>(pinnedLabel,tabKey,}) => {+ const closable = !pinned && !!onClose;+ const showClose = closable && active;++ // Middle click closes any closable tab β a shortcut on top of the active+ // tab's close button and the context menu, never the only way to close.+ const handleMouseDown = (e: MouseEvent) => {+ // keep the browser from entering autoscroll mode on middle press+ if (closable && e.button === 1) e.preventDefault();+ };+ const handleAuxClick = (e: MouseEvent) => {+ if (!closable || e.button !== 1) return;+ e.preventDefault();+ onClose?.();+ };+const content = (<divclassName={`${styles.container} ${active ? styles.containerActive : ''}`}data-pinned={pinned ? 'true' : undefined}+ onAuxClick={handleAuxClick}+ onMouseDown={handleMouseDown}><buttonaria-pressed={active}className={`${styles.tab} ${pinned ? styles.tabPinned : ''}`}data-tab-key={tabKey}+ title={typeof label === 'string' ? label : undefined}type="button"onClick={onSelect}><span className={styles.trigger}>- <span className={styles.icon} data-tab-icon={onClose && !pinned ? '' : undefined}>- {iconNode ?? <Icon icon={icon} size={14} />}+ <span className={styles.icon}>{iconNode ?? <Icon icon={icon} size={14} />}</span>+ <span+ className={styles.label}+ data-label={typeof label === 'string' ? label : undefined}+ >+ <span+ className={`${styles.labelText} ${showClose ? styles.labelTextBehindClose : ''}`}+ >+ {label}+ </span></span>- <span className={styles.label}>{label}</span></span></button>{pinned ? (<span aria-label={pinnedLabel} className={styles.pinned} role="img"><Icon icon={PinIcon} size={12} /></span>- ) : onClose ? (+ ) : showClose ? (+ // Only the selected tab exposes a close button, so dense strips of+ // short labels never fill up with close targets.<buttondata-tab-closearia-label={closeLabel}diff --git a/src/features/Conversation/WorkingSidebar/__tests__/index.test.tsx b/src/features/Conversation/WorkingSidebar/__tests__/index.test.tsxindex 561965b3b80..b8b3f6b96e2 100644--- a/src/features/Conversation/WorkingSidebar/__tests__/index.test.tsx+++ b/src/features/Conversation/WorkingSidebar/__tests__/index.test.tsx@@ -655,6 +655,40 @@ describe('AgentWorkingSidebar β tab strip', () => {expect(globalStore.toggleRightPanel).not.toHaveBeenCalled();});+ it('only exposes the close button on the selected tab', () => {+ localStorageState.openTabsByContext = {};+ globalStore.status.workingSidebarTab = 'skills';++ render(<AgentWorkingSidebar />);+ const skillsTab = screen.getByRole('button', { name: 'workingPanel.resources.filter.skills' });+ const documentsTab = screen.getByRole('button', {+ name: 'workingPanel.resources.filter.documents',+ });+ fireEvent.mouseOver(documentsTab);++ expect(skillsTab.parentElement!.querySelector('[data-tab-close]')).toBeInTheDocument();+ expect(documentsTab.parentElement!.querySelector('[data-tab-close]')).toBeNull();+ expect(document.querySelectorAll('[data-tab-close]')).toHaveLength(1);+ });++ it('closes an unselected tab on middle click', () => {+ localStorageState.openTabsByContext = {};+ globalStore.status.workingSidebarTab = 'skills';++ render(<AgentWorkingSidebar />);+ fireEvent(+ screen.getByRole('button', { name: 'workingPanel.resources.filter.documents' }),+ new MouseEvent('auxclick', { bubbles: true, button: 1 }),+ );++ expect(+ screen.queryByRole('button', { name: 'workingPanel.resources.filter.documents' }),+ ).not.toBeInTheDocument();+ expect(+ screen.getByRole('button', { name: 'workingPanel.resources.filter.skills' }),+ ).toHaveAttribute('aria-pressed', 'true');+ });+it('keeps the panel open and selects a surviving pinned tab when the active tab closes', () => {agentStore.activeAgentId = 'agent';localStorageState.openTabsByContext = { 'draft:agent:none': ['works', 'params'] };@@ -1068,7 +1102,12 @@ describe('AgentWorkingSidebar β tab strip', () => {expect(document.querySelector('button[data-tab-key="review"]')).toBeInTheDocument();});- fireEvent.click(document.querySelector('button[data-tab-key="review"]')!.nextElementSibling!);+ // the review tab is not the selected one, so it exposes no close button β+ // close it through the middle-click shortcut instead+ fireEvent(+ document.querySelector('button[data-tab-key="review"]')!,+ new MouseEvent('auxclick', { bubbles: true, button: 1 }),+ );expect(document.querySelector('button[data-tab-key="review"]')).not.toBeInTheDocument();globalStore.status.workingSidebarTabRequest = { nonce: 2, tab: 'review' };