Repository navigation
Let a programmatic runCommand leave focus where it is - #4
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes docker/learn#60.
Problem
After any command completes,
MockTerminalre-focuses its input. That suits typing, but a Run button that callshandle.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.RunCommandOptionsis 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: falseleaves focus on the Run button, and the skip does not carry over to the next run. They turn streaming on and run outsideact, 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