close
Skip to content

Keep focus on Provider select after Reset to default #532

Merged
dkotter merged 1 commit into
WordPress:developfrom
t-hamano:fix/reset-to-default-focus-loss
May 11, 2026
Merged

Keep focus on Provider select after Reset to default #532
dkotter merged 1 commit into
WordPress:developfrom
t-hamano:fix/reset-to-default-focus-loss

Conversation

@t-hamano
Copy link
Copy Markdown
Contributor

@t-hamano t-hamano commented May 9, 2026

See #180 (comment)

What?

  1. Move keyboard focus to the Provider select when the developer settings "Reset to default" button is clicked, so focus is not lost when the button unmounts.
  2. Make the disabled button focusable.

Why?

  1. The "Reset to default" button is rendered only while a saved provider/model selection exists. Clicking it clears the selection, which immediately removes the button from the DOM.
  2. The button becomes disabled the moment the provider is changed until the network communication is completed. Therefore, if the Tab key is pressed repeatedly immediately after changing the provider, users might miss the button without noticing it.

How?

  1. Wrap the DataForm in a ref-bearing <div> so we can locate the rendered Provider <select>. Unfortunately, the DataForm component itself does not support refs.
  2. Add accessibleWhenDisabled to the button so the focus target stays interactive while the save is in flight.

DataForm itself is a plain function component (not forwardRef), and the Field API has no ref hook for the underlying control, so wrapping with a ref + querySelector is the least invasive option.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.7
Used for: Drafting the focus-management change and this PR description; reviewed and edited by me.

Testing Instructions

  1. Enable the "Mode selection" setting.
  2. Pick a non-default Provider (and optionally a Model) so the "Reset to default" button appears.
  3. Immediately press the Tab key twice before the network communication finishes.
  4. The disabled button should then be focused.
  5. Click the button.
  6. Verify focus immediately moves to the Provider <select>.

Screenshots or screencast

Recording.2026-05-10.001712.mp4

Changelog Entry

Fixed - Keep keyboard focus on the Provider select when resetting per-feature developer settings to default.

Open WordPress Playground Preview

The Reset button disappears once settings are cleared because
hasSavedSelection becomes false, leaving keyboard focus orphaned on
the unmounted button. Move focus to the provider select before
triggering clear() so focus stays within the form.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@t-hamano t-hamano changed the title Fixed - Keep focus on Provider select after Reset to default in developer settings Keep focus on Provider select after Reset to default May 9, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.07%. Comparing base (6a02fe2) to head (92e13d7).

Additional details and impacted files
@@            Coverage Diff             @@
##             develop     #532   +/-   ##
==========================================
  Coverage      70.07%   70.07%           
  Complexity      1107     1107           
==========================================
  Files             67       67           
  Lines           5367     5367           
==========================================
  Hits            3761     3761           
  Misses          1606     1606           
Flag Coverage Δ
unit 70.07% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 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.

@t-hamano t-hamano marked this pull request as ready for review May 11, 2026 13:29
@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: t-hamano <wildworks@git.wordpress.org>

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

@dkotter dkotter added this to the 1.0.0 milestone May 11, 2026
@dkotter dkotter merged commit 5eee045 into WordPress:develop May 11, 2026
31 of 33 checks passed
@jeffpaul jeffpaul linked an issue May 18, 2026 that may be closed by this pull request
simison pushed a commit to simison/ai that referenced this pull request May 25, 2026
Fixed - Keep keyboard focus on the Provider select when resetting per-feature developer settings to default.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>
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.

Accessibility audit and fixes across AI Experiments UI

2 participants