Skip to content

Commit 377ed0a

Browse files
JasonWarrenUKclaude
andcommitted
fix(tui): align filter tab selection with default currentFilter
TabSelectRenderable has no constructor option for initial selection and always highlights index 0 (Errors) on mount, while the screen's currentFilter defaults to 'all'. This desynced the visible tab from the actually-displayed issue list. Explicitly select the "All" tab after construction, add setSelectedIndex to the TabSelectRenderable test double (previously missing), and extend the Tab focus test to cover the round-trip swap back. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent f9de587 commit 377ed0a

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/tui/screens/validation-explorer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ export class ValidationExplorerScreen implements Screen {
198198
{ name: 'All', description: '', value: 'all' },
199199
],
200200
});
201+
// TabSelectRenderable always highlights index 0 on mount; align it with currentFilter ('all').
202+
this.tabs.setSelectedIndex(2);
201203
this.filterPanel = panel(this.renderer, { title: 'Filter' });
202204
this.filterPanel.add(this.tabs);
203205
this.shell.content.add(this.filterPanel.box);

tests/fixtures/tui/opentui.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,14 @@ export class InputRenderable extends BaseRenderable {
125125
}
126126

127127
export class TabSelectRenderable extends BaseRenderable {
128+
selectedIndex = 0;
128129
on = vi.fn();
129130
focus = vi.fn();
130131
moveLeft = vi.fn();
131132
moveRight = vi.fn();
133+
setSelectedIndex = vi.fn(function (this: TabSelectRenderable, index: number) {
134+
this.selectedIndex = index;
135+
});
132136
}
133137

134138
export class ASCIIFontRenderable extends BaseRenderable {}

tests/tui/screens/validation-explorer.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@ describe('ValidationExplorerScreen', () => {
139139
screen.cleanup();
140140
});
141141

142+
it('aligns the tab bar selection with currentFilter (all) on mount', async () => {
143+
const screen = new ValidationExplorerScreen(mockContext);
144+
screen.render({ validation: validationWithIssues, sourceType: 'csv' });
145+
146+
await new Promise((resolve) => setTimeout(resolve, 10));
147+
148+
const tabs = (screen as any).tabs;
149+
expect(tabs.setSelectedIndex).toHaveBeenCalledWith(2);
150+
expect(tabs.selectedIndex).toBe(2);
151+
152+
screen.cleanup();
153+
});
154+
142155
it('rebuilds the issue list when the filter tab changes', async () => {
143156
const screen = new ValidationExplorerScreen(mockContext);
144157
screen.render({ validation: validationWithIssues, sourceType: 'csv' });
@@ -180,6 +193,11 @@ describe('ValidationExplorerScreen', () => {
180193
expect(issuesPanel.box.borderColor).toEqual(unfocusedColor);
181194
expect(detailPanel.box.borderColor).toEqual(focusedColor);
182195

196+
// Pressing Tab again swaps back to the original focused/unfocused state.
197+
handler({ name: 'tab' });
198+
expect(issuesPanel.box.borderColor).toEqual(focusedColor);
199+
expect(detailPanel.box.borderColor).toEqual(unfocusedColor);
200+
183201
screen.cleanup();
184202
});
185203

0 commit comments

Comments
 (0)