Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export interface ITerminalOptions {
convertEol?: boolean; // Convert \n to \r\n (default: false)
disableStdin?: boolean; // Disable keyboard input (default: false)

// Focus options
focusOnOpen?: boolean; // Auto-focus terminal on open (default: true)

// Scrolling options
smoothScrollDuration?: number; // Duration in ms for smooth scroll animation (default: 100, 0 = instant)

Expand Down
31 changes: 31 additions & 0 deletions lib/terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2989,4 +2989,35 @@ describe('Synchronous open()', () => {

term.dispose();
});

test('focusOnOpen: false prevents auto-focus on open', async () => {
if (!container) return;

// Focus a different element first
const other = document.createElement('input');
document.body.appendChild(other);
other.focus();
expect(document.activeElement).toBe(other);

const term = await createIsolatedTerminal({ focusOnOpen: false });
term.open(container);

// The terminal should NOT have stolen focus
expect(document.activeElement).toBe(other);

other.remove();
term.dispose();
});

test('focusOnOpen defaults to true', async () => {
if (!container) return;

const term = await createIsolatedTerminal();
term.open(container);

// The terminal should have taken focus
expect(document.activeElement).toBe(container);

term.dispose();
});
});
5 changes: 4 additions & 1 deletion lib/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class Terminal implements ITerminalCore {
convertEol: options.convertEol ?? false,
disableStdin: options.disableStdin ?? false,
smoothScrollDuration: options.smoothScrollDuration ?? 100, // Default: 100ms smooth scroll
focusOnOpen: options.focusOnOpen ?? true,
};

// Wrap in Proxy to intercept runtime changes (xterm.js compatibility)
Expand Down Expand Up @@ -526,7 +527,9 @@ export class Terminal implements ITerminalCore {
this.startRenderLoop();

// Focus input (auto-focus so user can start typing immediately)
this.focus();
if (this.options.focusOnOpen !== false) {
this.focus();
}
} catch (error) {
// Clean up on error
this.isOpen = false;
Expand Down