Skip to content

Set focus to the generated title text area upon modal open and completion - #901

Merged
dkotter merged 2 commits into
WordPress:developfrom
Infinite-Null:fix/ai-title-modal-focus-management
Jul 28, 2026
Merged

Set focus to the generated title text area upon modal open and completion#901
dkotter merged 2 commits into
WordPress:developfrom
Infinite-Null:fix/ai-title-modal-focus-management

Conversation

@Infinite-Null

@Infinite-Null Infinite-Null commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What?

Automatically sets focus to the generated title <textarea> inside the Title Generation modal when the modal opens and after a new title suggestion is regenerated.

Why?

When opening the Title Generation modal or clicking the "Regenerate" button, focus was not automatically placed on the generated title text field.

How?

  1. Added focusOnMount="firstInputElement" to the WordPress Modal component in TitleToolbar.tsx.
  2. Created a textAreaRef attached to the TextareaControl component.
  3. In handleRegenerate(), scheduled textAreaRef.current?.focus() via setTimeout(..., 0) tracked in focusTimeoutRef.current so focus is set to the text area once state updates complete and the input is re-enabled.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude
Model(s): Sonnet 4.6
Used for: Code review, PR description

Testing Instructions

  1. Open the post editor in WordPress with a post containing sufficient content.
  2. Click the Generate button in the title toolbar to open the AI Title Generation modal.
  3. Confirm that focus is automatically set inside the generated title text area upon opening.
  4. Click the Regenerate button inside the modal.
  5. Confirm that once title generation completes, focus is restored to the generated title text area.

Screencast:

Before:

Screen.Recording.2026-07-28.at.4.21.28.PM.mov

After:

Screen.Recording.2026-07-28.at.4.10.53.PM.mov

Changelog Entry

Fixed - Set focus to the generated title textarea when opening the title generation modal or regenerating a title.

Open WordPress Playground Preview

@Infinite-Null
Infinite-Null requested a review from a team July 28, 2026 10:52
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Infinite-Null <ankitkumarshah@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.18%. Comparing base (5a1a1da) to head (f858db8).

Additional details and impacted files
@@            Coverage Diff             @@
##             develop     #901   +/-   ##
==========================================
  Coverage      80.18%   80.18%           
  Complexity      2526     2526           
==========================================
  Files            106      106           
  Lines          10240    10240           
==========================================
  Hits            8211     8211           
  Misses          2029     2029           
Flag Coverage Δ
unit 80.18% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dkotter dkotter added this to the 1.3.0 milestone Jul 28, 2026
@dkotter
dkotter merged commit f8214b0 into WordPress:develop Jul 28, 2026
24 checks passed
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.

2 participants