Skip to content

DataViews: Move bulk selection focus only on request from an interaction - #86932

Merged
t-hamano merged 12 commits into
trunkfrom
fix/dataviews-event-driven-selection-focus
Nov 19, 2026
Merged

t-hamano merged 12 commits into
trunkfrom
fix/dataviews-event-driven-selection-focus

Conversation

@t-hamano

@t-hamano t-hamano commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What?

See #86701, #86700

Replaces the "focus is on the document body" check in the table and grid layouts with focus requests made by the interactions that change the selection.

site-editor-v1-table-select-all-cancel.mp4

Why?

Since #82730, the table and grid layouts move focus to a selection checkbox when the selection is cleared and focus is on the document body. This is meant for the case where the Cancel button removes the bulk actions toolbar along with the focused element. But the useEffect only depends on whether there is a selection, so it can't tell why focus was lost. It also moves focus when focus was lost for another reason, such as a navigation that re-renders the page.

This conflicts with #86701, which moves focus to the page region after a navigation loses focus. In the page list, clearing the selection is also a navigation, so both try to recover focus, and the page region wins.

How?

Instead of checking for focus on the document body, the interactions that change the selection (Cancel and the select all checkbox) ask a new internal hook, useBulkActionsFocus, to move focus. The hook moves focus once the bulk actions toolbar is shown or hidden.

Testing Instructions

  1. Go to Appearance > Editor > Pages.
  2. In the Table layout, check "Select all" in the table header. Focus moves to "Deselect all" in the toolbar.
  3. Press Cancel in the toolbar. Focus returns to "Select all" in the table header.
  4. Switch to the Grid layout, select all items, and press Cancel. Focus moves to "Select all" in the toolbar.

Use of AI Tools

Implemented with Claude Code, reviewed by the author.


Generated by Claude Code

claude and others added 2 commits November 17, 2026 07:34
The table and grid layouts moved focus to a selection checkbox whenever the
selection was cleared while focus was on the document body. That guess also
claimed focus that something else lost, such as an app router that moves
focus after a navigation, and ran after the router did.

Record the focus target when the user clears the selection, selects all
items from the table header, or finishes a bulk action, and move focus once
the toolbar reaches the expected state. The move runs in a layout effect, so
it happens before the effects of ancestors.

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

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>
Co-authored-by: aduth <aduth@git.wordpress.org>

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: -142 B (0%)

Total Size: 8.68 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 556 kB +17 B (0%)
build/scripts/edit-site/index.min.js 382 kB -102 B (-0.03%)
build/scripts/editor/index.min.js 572 kB -44 B (-0.01%)
build/scripts/media-utils/index.min.js 238 kB -13 B (-0.01%)

5da60fc Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric ce6cf80 trunk % Change
timeToFirstByte 58.6 ms +10.58% -2.9% 58.1 ms +7.75% -6.71% 0.86%
largestContentfulPaint 98 ms +2.04% -10.2% 90 ms +11.11% -4.44% 8.89%
lcpMinusTtfb 32.5 ms +20.92% -6.46% 30.4 ms +28.78% -5.26% 6.91%
wpBeforeTemplate 30.74 ms +16.79% -2.77% 29.7 ms +10.27% -5.35% 3.5%
wpTemplate 23.35 ms +8.65% -2.23% 22.94 ms +6.5% -5.27% 1.79%
wpTotal 54.63 ms +10.98% -3.28% 54.27 ms +7.19% -7.43% 0.66%
wpMemoryUsage 7.75 MB +0% -0% 7.71 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric ce6cf80 trunk % Change
timeToFirstByte 48.6 ms +4.84% -2.26% 47.65 ms +4.83% -3.99% 1.99%
largestContentfulPaint 84 ms +2.38% -0% 84 ms +4.76% -4.76% 0%
lcpMinusTtfb 36.3 ms +2.2% -3.17% 34.8 ms +4.17% -1.58% 4.31%
wpBeforeTemplate 27.26 ms +6.38% -1.32% 26.9 ms +5.69% -2.04% 1.34%
wpTemplate 17.49 ms +2.63% -1.49% 16.79 ms +7.27% -2.44% 4.17%
wpTotal 44.92 ms +6.19% -1.51% 44.31 ms +5.57% -3.77% 1.38%
wpMemoryUsage 6.44 MB +0% -0% 6.40 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric ce6cf80 trunk % Change
mediaProcessingJpeg 408.13 ms +1.41% -0.36% 401.89 ms +1.42% -1.26% 1.55%
mediaProcessingAvif 6231.13 ms +0.24% -0.75% 6155.28 ms +0.38% -0.07% 1.23%
mediaProcessingJpegToAvif 4269.79 ms +0.31% -0.07% 4248.29 ms +0.28% -0.17% 0.51%

media-upload

Metric ce6cf80 trunk % Change
jpegUploadProcessing 2052.88 ms +0.29% -2.85% 1962.26 ms +1.2% -23.14% 4.62%
pngUploadProcessing 287.42 ms +0.78% -2.93% 265.73 ms +2.37% -5.35% 8.16%
largeJpegUploadProcessing 1997.59 ms +0.7% -1.2% 1976.93 ms +1.11% -21.91% 1.05%
multipleImageUploadProcessing 2117.66 ms +0.33% -0.47% 2047.23 ms +1.92% -0.31% 3.44%

post-editor

Metric ce6cf80 trunk % Change
serverResponse 337.18 ms +3.66% -11.39% 328.29 ms +1.6% -9.24% 2.71%
firstPaint 360.83 ms +4.59% -4% 350.02 ms +6.57% -8.16% 3.09%
domContentLoaded 663.36 ms +2.32% -0.74% 668.95 ms +2.47% -0.56% -0.84%
loaded 664.43 ms +2.31% -0.74% 669.84 ms +2.48% -0.57% -0.81%
firstContentfulPaint 377.3 ms +0.94% -1.43% 382.38 ms +2.72% -2.45% -1.33%
firstBlock 1742.27 ms +3.19% -0.9% 1766.68 ms +1.44% -1.14% -1.38%
type 16.53 ms +2.48% -10.53% 16.07 ms +6.41% -9.52% 2.86%
typeWithoutInspector 15.69 ms +2.36% -12.36% 16.34 ms +10.65% -8.75% -3.98%
typeWithTopToolbar 19.7 ms +4.06% -13.5% 19.62 ms +7.19% -7.29% 0.41%
typeContainer 6.71 ms +12.07% -5.96% 7.04 ms +3.41% -11.51% -4.69%
focus 107.78 ms +2.42% -8.88% 98.23 ms +4.28% -3.99% 9.72%
firstFocus 229.49 ms +0% -0% 223.21 ms +0% -0% 2.81%
selectAll 328.5 ms +3.25% -0.81% 313.77 ms +0.76% -0.45% 4.69%
undo 25.3 ms +7.11% -3.08% 25.28 ms +8.19% -4.43% 0.08%
listViewOpen 63.86 ms +7.52% -4.4% 62.02 ms +10.82% -5.69% 2.97%
inserterOpen 36.11 ms +6.81% -3.07% 35.66 ms +3.93% -10.43% 1.26%
inserterHover 10.14 ms +3.35% -9.57% 10 ms +7.4% -6.2% 1.4%
inserterSearch 7.36 ms +4.08% -5.43% 6.68 ms +18.86% -3.74% 10.18%
loadPatterns 529.15 ms +1.27% -1.76% 521.72 ms +2.54% -4.15% 1.42%
wpTotal 328.02 ms +3.57% -11.54% 319.71 ms +1.63% -9.49% 2.6%
wpMemoryUsage 14.81 MB +0% -0% 14.77 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric ce6cf80 trunk % Change
serverResponse 294.91 ms +1.07% -4.22% 275.8 ms +3.17% -7.54% 6.93%
firstPaint 363.88 ms +6.24% -12.59% 315.35 ms +9.06% -10.89% 15.39%
domContentLoaded 668.42 ms +2.34% -2.37% 603.16 ms +1.11% -1.79% 10.82%
loaded 669.4 ms +2.34% -2.36% 604.03 ms +1.12% -1.8% 10.82%
firstContentfulPaint 376.37 ms +2.72% -3.81% 344.63 ms +1.96% -1.92% 9.21%
firstBlock 2029.8 ms +2.99% -1.58% 1838.58 ms +2.28% -2.47% 10.4%
type 15.93 ms +9.1% -7.47% 14.03 ms +9.98% -2.64% 13.54%
navigate 90.46 ms +8.87% -2.5% 87.38 ms +5.41% -7.8% 3.52%
loadPatterns 1057.05 ms +3.24% -9.4% 1098.01 ms +5.82% -7.68% -3.73%
loadPages 935.77 ms +0.47% -0.86% 968.55 ms +1.79% -1.5% -3.38%
wpTotal 288 ms +0.95% -4.47% 269 ms +3.28% -7.77% 7.06%
wpMemoryUsage 12.82 MB +0% -0% 12.79 MB +0% -0% 0.25%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

5da60fc Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

does not double up an event React already delivers in /test/e2e/specs/editor/various/editable-root-compat.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/editable-root-compat.spec.js:291:5
keeps the default tab on the moved tab in /test/e2e/specs/editor/blocks/tabs.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

Expected: 0
Received: 1

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/tabs.spec.js:736:60

5da60fc Run

@github-actions github-actions Bot added the [Package] DataViews /packages/dataviews label Nov 17, 2026
@t-hamano t-hamano self-assigned this Nov 17, 2026
@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). labels Nov 17, 2026
claude and others added 7 commits November 17, 2026 07:38
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4

@aduth aduth left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Seems like a better technical direction to directly handle these known interactions and focus fallbacks stemming from the component's own rendering behavior.

Do we (should we) have some test coverage for this?

Comment on lines +27 to +32
// Layout effects run before the effects of ancestors, such as a router
// that moves focus when a navigation removes the focused element.
useLayoutEffect( () => {
targetRef.current?.current?.focus();
targetRef.current = null;
}, [ isShown ] );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is simple and matches the typical behavior we'd expect, but it's also somewhat a loose dependency between "trigger focus from close request" and "is bulk actions shown", and that the former necessarily triggers the latter. I don't know if there's actual scenarios we have to worry about here where toolbar visibility changes independently, or if e.g. selection changes asynchronously from the click on the button (e.g. if trashing triggers a network request and only changes selection after the network request).

It looks like your initial commit handled this a bit more exhaustively at the cost of extra complexity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s right. I initially tried to handle every case, but I wasn’t sure it was worth it, and the code got quite complex, so I simplified it in 0c2a4c5. That commit also removed the focus request after a bulk action, so the only remaining triggers are Cancel and the select all checkbox. Both should toggle the toolbar immediately, so I don’t expect the async case to happen.

@t-hamano

t-hamano commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

@aduth Thanks for the review!

Do we (should we) have some test coverage for this?

We already have browser tests in bulk-selection.browser.test.tsx that cover the focus moves in the table layout. I'll add a test for the case where the selection is cleared without an interaction, to make sure focus doesn't move.

claude and others added 3 commits November 19, 2026 02:49
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URz5qnxZyAFDMiJeNWv
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URz5qnxZyAFDMiJeNWv
@t-hamano
t-hamano merged commit 0a22ca0 into trunk Nov 19, 2026
86 of 87 checks passed
@t-hamano
t-hamano deleted the fix/dataviews-event-driven-selection-focus branch November 19, 2026 03:34
@github-actions github-actions Bot added this to the Gutenberg 24.6 milestone Nov 19, 2026
Vedant-Gandhi pushed a commit to Vedant-Gandhi/gutenberg that referenced this pull request Nov 30, 2026
…ion (WordPress#86932)

* DataViews: Move bulk selection focus only on request from an interaction

The table and grid layouts moved focus to a selection checkbox whenever the
selection was cleared while focus was on the document body. That guess also
claimed focus that something else lost, such as an app router that moves
focus after a navigation, and ran after the router did.

Record the focus target when the user clears the selection, selects all
items from the table header, or finishes a bulk action, and move focus once
the toolbar reaches the expected state. The move runs in a layout effect, so
it happens before the effects of ancestors.

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4

* Add changelog entry

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4

* Remove redundant comments

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4

* Remove redundant comments

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4

* Remove the added browser tests

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4

* Inline the table focus request

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4

* Pass an object to useBulkActionsFocus

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4

* Remove the focus request after a bulk action

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4

* Rename requestFocus to focusAfterToggle

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyzU5uLZFCXsBBvXn4

* Add a test for clearing the selection without an interaction

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URz5qnxZyAFDMiJeNWv

* Move the changelog entry to Unreleased

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URz5qnxZyAFDMiJeNWv

---------

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] DataViews /packages/dataviews [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants