Repository navigation
Writing flow: enter the Search block's side by side fields at the caret column in both directions - #85555
Draft
mtias wants to merge 3 commits into
Draft
Writing flow: enter the Search block's side by side fields at the caret column in both directions#85555mtias wants to merge 3 commits into
mtias wants to merge 3 commits into
Conversation
Arrowing down through a Search block visited label, input, next block, while arrowing up from the next block visited button, label: the fields reached depended on the direction. `getClosestTabbable` returned the first focusable in DOM order (reversed when going up) that horizontally overlaps the current element. The Search label and the paragraph after the block span the full width, so both fields of the input + button row overlap them and DOM order picked the input going down and the button going up. The same happens for every side by side layout (columns, buttons, flex groups). The hook already remembers the caret's horizontal position on the first vertical key press to restore it in the target, recreating how a caret keeps its column in a browser. Use that position to choose the target too: among the candidates that form the row reached (the first one in DOM order and the later ones that overlap it vertically without being nested in it), prefer the one under the caret; ties, an unknown position and Alt (which goes to the furthest edge) keep DOM order. This is symmetric by construction for a given column. "Should navigate inner blocks with arrow keys" now enters the first column from the end of "Second paragraph", which lies under it, instead of the last column; the expectation is updated. Considered and rejected: always taking the DOM-first field of the row in both directions (makes the button unreachable with the arrow keys and is not what a caret does), and a Search-specific special case. Refs #38261 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The previous commit chose the field under the caret among every candidate in the row reached, which changed how the arrow keys enter rows of blocks: Columns were entered at the column under the caret instead of the DOM-first/last one (a writing-flow expectation re-asserted in #75141 and #81456), ArrowDown into a Buttons block could land on its inline appender (rendered once the wrapper is selected, and the closest focusable to the caret), and uneven Columns could skip a paragraph on the way up. Scope the scan to the content of the block the DOM-first candidate belongs to (`isInsideRootBlock`: not its inner blocks, not its appenders), and stop once the walk leaves that block, since a block's descendants are contiguous in DOM order. The Search block's input and button are one block, so #38261 is fixed as reported; rows of blocks (Columns, Buttons, Gallery) and block placeholders behave exactly as before, and `Should navigate inner blocks with arrow keys` keeps its "2nd col" expectation. Entering a row of blocks at the caret column is a reasonable extension of the same idea, but it is the writing-flow maintainers' call and needs its own design pass (which element bounds the row, appenders, uneven columns); it is left as a proposal. The new e2e test also covers the caret under the button, the issue's second complaint ("Add button text" skipped on the way down). Refs #38261 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🤖 PR meta 🤖🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. 📦 Bundle sizeSize Change: +192 B (0%) Total Size: 9.07 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
|
The Unreleased entry linked issue #38261, and CI's changelog validation requires every Unreleased entry to link a Gutenberg pull request. Point it at #85555 now that the PR exists, and name the other side by side fields of one block the change applies to (Table cells, placeholder buttons), as the review asked. Refs #38261 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This branch has not been deployed
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.
What?
Closes #38261.
When the up or down arrow key moves the caret into a row of side-by-side fields that belong to one block (the Search block's input and button), writing flow now lands on the field under the caret instead of the first one in DOM order going down and the last one going up. The same fields are visited in both directions.
Why?
In the Search block, pressing ArrowDown from the paragraph above visits label → input → next paragraph, while pressing ArrowUp from the paragraph below visits button → label. The button can never be reached with the arrow keys from above, the input never from below, and the round trip is not a mirror image (reported in #38261, re-confirmed on trunk in August 2026).
The cause is in
getClosestTabbable(packages/block-editor/src/components/writing-flow/use-arrow-nav.ts): it returns the first focusable in DOM order (reversed when going up) that horizontally overlaps the current element. The label above the row and the paragraph below it span the full width, so both the input and the button overlap them, and DOM order decides: the input wins going down, the button going up. The direction, not the caret position, picks the field.How?
The hook already remembers the caret's horizontal position for vertical moves (
verticalRect, used byplaceCaretAtVerticalEdgeto keep the x column, "recreate browser behaviour"). This PR passes that x intogetClosestTabbableas an optional last argument. After finding the DOM-first candidate, the function scans the focusables that follow it within the same block's own content (isInsideRootBlock: inner blocks and appenders are excluded; the walk stops as soon as it leaves the block, since a block's descendants are contiguous in DOM order) for elements in the same visual row, and keeps the one horizontally closest to x. Strict<means DOM order breaks ties; with Alt, or when there is no caret rect, x isundefinedand behaviour is unchanged.Scoping to one block is deliberate. A first version applied the rule to any row (Columns, Buttons, Gallery…) and changed the long-standing
'2nd col'expectation inwriting-flow.spec.js(re-asserted in #75141 and #81456). Review found it could land ArrowDown on the Buttons block's inline appender and skip a paragraph in uneven Columns, and that entry order for rows of blocks is a design decision for the writing-flow maintainers, so this PR leaves it alone: rows of blocks enter at the DOM-first block exactly as on trunk. The general "enter a row at the caret column" idea is a possible follow-up, not part of this change.Besides the Search block, the other "side-by-side fields of one block" affected are the cells of a Table row and the buttons of a block placeholder (e.g. an empty Image block's Upload / Media Library / Insert from URL); they are now entered at the caret column too.
Considered and rejected: always DOM-first in both directions (symmetric, but the Search button becomes unreachable with Up/Down), and a Search-specific special case (the asymmetry is generic to the hook, not the block).
Reviewer notes:
getClosestTabbableresolves the block wrapper withownerDocument.getElementById( 'block-' + clientId )!;first.closest( BLOCK_SELECTOR )would be the same element without the non-null assertion, if preferred.Testing Instructions
Testing Instructions for Keyboard
The steps above are keyboard-only apart from placing the caret.
Automated:
npm run test:unit -- packages/block-editor/src/components/writing-flow(newgetClosestTabbabletests, including the appender exclusion and DOM order for a row of blocks), and the new e2e testshould navigate side by side fields in the same order up and downintest/e2e/specs/editor/various/writing-flow.spec.js, which fails on trunk.Screenshots or screencast
Recorded in Chromium on the built plugin; each clip is ArrowDown from the first paragraph to the second, then ArrowUp back.
Verification and what was not run
npm run lint:js,tsc --noEmit,npm run build: clean.writing-flow.spec.jspasses all arrow-key tests (two failures unrelated to arrow keys are identical on trunk and specific to the local theme); a sequence-recording spec over Columns, uneven Columns, Buttons and Search is identical to trunk except for the Search block's up-from-below step.describeis tagged@firefox, @webkit, so CI covers them); Navigation, Social Links, Gallery and block placeholders were reasoned about from the code, not driven.🤖 Generated with Claude Code