Skip to content

Fix stage direction text input not auto-focusing on add (#1017)#1019

Merged
Tim020 merged 2 commits into
devfrom
fix/stage-direction-autofocus-1017
May 12, 2026
Merged

Fix stage direction text input not auto-focusing on add (#1017)#1019
Tim020 merged 2 commits into
devfrom
fix/stage-direction-autofocus-1017

Conversation

@Tim020
Copy link
Copy Markdown
Contributor

@Tim020 Tim020 commented May 12, 2026

Summary

Root Cause

Bootstrap Vue's b-dropdown-item uses this sequence on click:

  1. Emits the click event → addStageDirection() runs
  2. Calls closeDropdown()requestAnimationFrame(() => bvDropdown.hide(true))

hide(true) triggers focusToggler(), which uses $nextTick to restore focus to the toggle button. A plain $nextTick in ScriptLinePart.mounted() ran before the dropdown's rAF fired, so the dropdown's subsequent focusToggler → $nextTick stole focus back.

Fix

Use requestAnimationFrame + $nextTick in ScriptLinePart.mounted():

  • ScriptLinePart mounts as part of Vue's reactive flush (microtask phase), before any animation frame fires
  • Our requestAnimationFrame is therefore registered after the dropdown's rAF but in the same frame, so it fires second
  • Our $nextTick is then queued after focusToggler's $nextTick, meaning our input focus wins

Test plan

  • Add a new stage direction — cursor should immediately appear in the text input without clicking
  • Add a new dialogue line — same auto-focus behaviour confirmed
  • Click "Edit" on an existing stage direction — cursor should appear in the first text input
  • npm run typecheck passes
  • npm run lint passes

🤖 Generated with Claude Code

Wrap the focus() call in $nextTick so it fires after Vue's DOM update
cycle is fully committed. When a new stage direction is added,
ScriptLineEditor.created() is async — it awaits previousLineFn before
calling addLinePart(), so ScriptLinePart mounts during a reactive
re-render rather than the initial mount sequence. A synchronous focus()
during mid-flush is unreliable; deferring to $nextTick fixes this.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Tim020 Tim020 added the claude Issues created by Claude label May 12, 2026
@github-actions github-actions Bot added client Pull requests changing front end code xsmall-diff labels May 12, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 12, 2026

Client Test Results

106 tests   106 ✅  0s ⏱️
  5 suites    0 💤
  1 files      0 ❌

Results for commit 499f787.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 12, 2026

Python Test Results

  1 files    1 suites   1m 21s ⏱️
587 tests 587 ✅ 0 💤 0 ❌
592 runs  592 ✅ 0 💤 0 ❌

Results for commit 499f787.

♻️ This comment has been updated with latest results.

@Tim020 Tim020 linked an issue May 12, 2026 that may be closed by this pull request
Bootstrap Vue's b-dropdown-item calls closeDropdown() → requestAF(() =>
hide(true)) after emitting the click. hide(true) triggers focusToggler()
which uses $nextTick to restore focus to the toggle button. This ran after
our plain $nextTick, stealing focus from the newly added input.

Fix: use requestAnimationFrame + $nextTick in ScriptLinePart.mounted().
Our rAF is registered during the post-click microtask phase (ScriptLinePart
mounts as part of Vue's reactive flush), so it fires after the dropdown's
earlier-registered rAF in the same animation frame. Our subsequent $nextTick
is therefore queued after focusToggler's $nextTick, so input focus wins.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added small-diff Small pull request and removed xsmall-diff labels May 12, 2026
@sonarqubecloud
Copy link
Copy Markdown

@Tim020 Tim020 merged commit 23c6bc0 into dev May 12, 2026
26 checks passed
@Tim020 Tim020 deleted the fix/stage-direction-autofocus-1017 branch May 12, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude Issues created by Claude client Pull requests changing front end code small-diff Small pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding new stage direction should default cursor into text entry

1 participant