Skip to content

Commit 421443d

Browse files
authored
Merge pull request #335 from DalgoT4D/fix/single-tab-rename
fix: allow renaming dashboard tab when only one tab exists
2 parents 62a34e8 + 1b1ba89 commit 421443d

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

components/dashboard/tabs/TabBar.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,15 @@ const TabItem = memo(function TabItem({
6464
}, [isEditing, onSelect, tab.id]);
6565

6666
// Handle single click on title to start editing
67-
// Disabled when there is only one tab
6867
const handleTitleClick = useCallback(
6968
(e: React.MouseEvent) => {
70-
if (isEditMode && isActive && !isOnlyTab) {
69+
if (isEditMode && isActive) {
7170
e.stopPropagation();
7271
setEditValue(tab.title);
7372
setIsEditing(true);
7473
}
7574
},
76-
[isEditMode, isActive, isOnlyTab, tab.title]
75+
[isEditMode, isActive, tab.title]
7776
);
7877

7978
// Handle rename completion
@@ -162,14 +161,12 @@ const TabItem = memo(function TabItem({
162161
type="button"
163162
className={cn(
164163
'truncate max-w-32 text-sm bg-transparent border-none p-0',
165-
isEditMode && isActive && !isOnlyTab
166-
? 'cursor-pointer hover:underline'
167-
: 'cursor-default'
164+
isEditMode && isActive ? 'cursor-pointer hover:underline' : 'cursor-default'
168165
)}
169166
data-testid={`tab-title-${tab.id}`}
170167
onClick={handleTitleClick}
171168
aria-label={`Rename ${tab.title} tab`}
172-
tabIndex={isEditMode && isActive && !isOnlyTab ? 0 : -1}
169+
tabIndex={isEditMode && isActive ? 0 : -1}
173170
>
174171
{tab.title}
175172
</button>

components/dashboard/tabs/__tests__/TabBar.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,22 @@ describe('TabBar', () => {
7474
await user.keyboard('{Enter}');
7575
expect(defaultProps.onTabRename).toHaveBeenCalledWith('tab-1', 'New Name');
7676
});
77+
78+
it('renames the only tab on title click (single-tab dashboard)', async () => {
79+
const user = userEvent.setup();
80+
render(
81+
<TabBar
82+
{...defaultProps}
83+
tabs={[makeTab('tab-1', 'Tab 1')]}
84+
activeTabId="tab-1"
85+
isEditMode={true}
86+
/>
87+
);
88+
await user.click(screen.getByTestId('tab-title-tab-1'));
89+
const input = screen.getByTestId('tab-rename-input-tab-1');
90+
await user.clear(input);
91+
await user.type(input, 'Renamed');
92+
await user.keyboard('{Enter}');
93+
expect(defaultProps.onTabRename).toHaveBeenCalledWith('tab-1', 'Renamed');
94+
});
7795
});

0 commit comments

Comments
 (0)