Skip to content

Let a programmatic runCommand leave focus where it is - #4

Merged
mikesir87 merged 1 commit into
mainfrom
fix/run-command-no-refocus
Oct 23, 2026
Merged

mikesir87 merged 1 commit into
mainfrom
fix/run-command-no-refocus

Conversation

@mikesir87

Copy link
Copy Markdown
Member

Fixes docker/learn#60.

Problem

After any command completes, MockTerminal re-focuses its input. That suits typing, but a Run button that calls handle.runCommand() pulls focus off the button too. On a touch device that opens the keyboard, and iOS Safari zooms in because the input's font size is under 16px. It is jarring, and it also moves the page away from the output the learner wanted to read.

Change

runCommand(text, { focus?: boolean }) takes an optional second argument. { focus: false } skips the post-command refocus for that run. The default is unchanged, so typed commands and existing callers behave as before. RunCommandOptions is exported from @dockersamples/simspace-simulator/react.

The skip is set at the start of each run, so a skipped refocus cannot leak into the next one.

Tests

Three new tests: the default still refocuses, focus: false leaves focus on the Run button, and the skip does not carry over to the next run. They turn streaming on and run outside act, because the refocus only fires when the input unmounts for a render, and a command that finishes instantly never does. Typecheck and all 189 tests pass.

Follow-up in Learn once this merges: bump the pinned revision and pass { focus: false } from the Run button.

🤖 Generated with Claude Code

After any command the terminal re-focuses its input. That suits typing, but
a Run button that calls runCommand() pulled focus off the button too, which
on a touch device opens the keyboard and makes the browser zoom and scroll.

runCommand now takes { focus?: boolean }. The default is unchanged; callers
that are Run buttons pass { focus: false }.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@mikesir87
mikesir87 merged commit 8d40bf1 into main Oct 23, 2026
2 checks passed
@mikesir87
mikesir87 deleted the fix/run-command-no-refocus branch October 23, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant