Repository navigation
Description
Description
Following up from the PR comment here - #80306 (comment),
🤖 Claude Code Generate it for me
In the DataViews list layout, removing the row that currently has focus drops focus to <body>. Keyboard and screen-reader users lose their place in the list and have to tab back from the top of the page after every deletion.
The layout already tries to handle this. packages/dataviews/src/components/dataviews-layouts/list/index.tsx has an effect whose comment states the intent:
Select a new active composite item when the current active item is removed from the list.
By pickingpreviousActiveItemIndex[…] we are basically picking the item that would have been after the deleted one. If the previously active (and removed) item was the last of the list, we will select the item before it — which is the new last item.
That effect calls selectCompositeItem(), which moves DOM focus only when focus is still inside the list:
// The active composite item is controlled state that can update without needing a
// focus move (e.g., searching can trigger an active ID update). Only move DOM focus
// when it's already within the list.
if ( compositeRef.current?.contains(
compositeRef.current.ownerDocument.activeElement ) ) {
document.getElementById( targetCompositeItemId )?.focus();
}By the time the effect runs, the removed row is unmounted, so activeElement is already <body> — the guard is false and the focus move is skipped. The active composite id is updated (so the next Tab into the list lands in the right place), but focus itself is lost in the moment that matters.
The guard is correct for the case it was written for (search re-ordering the list must not steal focus). Removal is a different case that needs to be distinguished from it.
What is your proposed solution?
Let the removal path move DOM focus when focus was inside the list immediately before the row disappeared:
- Track whether the composite held focus just before the data change — e.g. a ref updated on the composite's
focusin/focusout, rather than readingactiveElementafter the fact. - Give
selectCompositeItem()an opt-in to force the focus move, and use it only from the item-removed effect. Every other caller keeps today's behavior. - Only force it when focus is actually orphaned —
activeElementisnull,<body>, or inside the unmounted row. If the user has since moved focus somewhere real, or a dialog is open and owns focus return, do nothing.
Point 3 matters because removal is often confirmed in a modal: the dialog's own focus return should win, and DataViews should not fight it.
Worth deciding as part of this: whether the other layouts (grid, table) need the same treatment, and what should happen when the removed row was the only one on the last page.
Step-by-step reproduction instructions
- Open site-editor/pages
- Delete/Trash any page from the list
- Check the focus is now moved to body, but it should fallback to next/previous element.
Screenshots, screen recording, code snippet
Screen.Recording.2026-08-31.at.3.25.46.PM.mov
Environment info
- WP Latest.
- GB Trunk.
Please confirm that you have searched existing issues in the repo.
- Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
- Yes
Please confirm which theme type you used for testing.
- Block
- Classic
- Hybrid (e.g. classic with theme.json)
- Not sure
Activity
[-]DataViews: focus is lost when the focused row is removed from the list layout[/-][+]DataViews: focus is lost when the focused row is removed from the list/table layout[/+]raoazwar commentedon Sep 2, 2026
Hey, I just tried to reproduce the issue on my local server, but I wasn’t able to reproduce the issue shown in your video.
Recording.2026-09-03.003406.1.mp4