From a07adff0522e965fe0d52b294ca9652d2710e71d Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 09:12:07 +0530 Subject: [PATCH 01/26] DataViews: Name the action in selection checkbox labels --- .../dataviews-selection-checkbox/index.tsx | 11 +- .../test/bulk-selection.browser.test.tsx | 2 +- .../dataviews/test/dataviews.jsdom.test.tsx | 116 +++++++++++++----- 3 files changed, 94 insertions(+), 35 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-selection-checkbox/index.tsx b/packages/dataviews/src/components/dataviews-selection-checkbox/index.tsx index 8cdf51099e5a57..b9add108619e98 100644 --- a/packages/dataviews/src/components/dataviews-selection-checkbox/index.tsx +++ b/packages/dataviews/src/components/dataviews-selection-checkbox/index.tsx @@ -1,5 +1,5 @@ import { Checkbox } from '@wordpress/ui'; -import { __ } from '@wordpress/i18n'; +import { __, sprintf } from '@wordpress/i18n'; import type { SetSelection } from '../../types/private'; import type { NormalizedField } from '../../types'; @@ -29,9 +29,12 @@ export default function DataViewsSelectionCheckbox< Item >( { const isInSelectionArray = selection.includes( id ); const checked = ! disabled && isInSelectionArray; - // Fallback label to ensure accessibility - const selectionLabel = - titleField?.getValue?.( { item } ) || __( '(no title)' ); + // Name the action as well as the item, as the list tables do. + const selectionLabel = sprintf( + /* translators: %s: The title of the item. */ + __( 'Select %s' ), + titleField?.getValue?.( { item } ) || __( '(no title)' ) + ); return ( { // First item should be selected. expect( - screen.getByRole( 'checkbox', { name: data[ 0 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 0 ].title }`, + } ) ).toBeChecked(); await user.click( thirdItemElement ); // Both items should be selected. expect( - screen.getByRole( 'checkbox', { name: data[ 0 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 0 ].title }`, + } ) ).toBeChecked(); expect( - screen.getByRole( 'checkbox', { name: data[ 2 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 2 ].title }`, + } ) ).toBeChecked(); // Don't keep the modifier pressed down, that's just mean. @@ -824,7 +830,9 @@ describe( 'DataViews component', () => { await user.click( screen.getByText( data[ 0 ].title ) ); await user.keyboard( '{/Control}' ); expect( - screen.getByRole( 'checkbox', { name: data[ 0 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 0 ].title }`, + } ) ).toBeChecked(); // Shift+Click selects everything between the anchor and the @@ -833,7 +841,9 @@ describe( 'DataViews component', () => { await user.click( screen.getByText( data[ 2 ].title ) ); for ( const item of data ) { expect( - screen.getByRole( 'checkbox', { name: item.title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ item.title }`, + } ) ).toBeChecked(); } @@ -856,10 +866,14 @@ describe( 'DataViews component', () => { // Checkbox clicks select the first and third items; the third // becomes the anchor. await user.click( - screen.getByRole( 'checkbox', { name: data[ 0 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 0 ].title }`, + } ) ); await user.click( - screen.getByRole( 'checkbox', { name: data[ 2 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 2 ].title }`, + } ) ); // Shift+Click applies the anchor's state to the range without @@ -870,7 +884,9 @@ describe( 'DataViews component', () => { await user.keyboard( '{/Shift}' ); for ( const item of data ) { expect( - screen.getByRole( 'checkbox', { name: item.title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ item.title }`, + } ) ).toBeChecked(); } } ); @@ -893,7 +909,9 @@ describe( 'DataViews component', () => { ); // Unchecking the third item makes it the anchor. await user.click( - screen.getByRole( 'checkbox', { name: data[ 2 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 2 ].title }`, + } ) ); // Shift-clicking the selected second item selects the range @@ -903,7 +921,9 @@ describe( 'DataViews component', () => { await user.keyboard( '{/Shift}' ); for ( const item of data ) { expect( - screen.getByRole( 'checkbox', { name: item.title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ item.title }`, + } ) ).toBeChecked(); } } ); @@ -924,10 +944,14 @@ describe( 'DataViews component', () => { // Selecting and deselecting the first item leaves it as the // anchor with nothing selected. await user.click( - screen.getByRole( 'checkbox', { name: data[ 0 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 0 ].title }`, + } ) ); await user.click( - screen.getByRole( 'checkbox', { name: data[ 0 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 0 ].title }`, + } ) ); // Shift-clicking the unselected third item selects the whole @@ -937,7 +961,9 @@ describe( 'DataViews component', () => { await user.keyboard( '{/Shift}' ); for ( const item of data ) { expect( - screen.getByRole( 'checkbox', { name: item.title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ item.title }`, + } ) ).toBeChecked(); } } ); @@ -958,7 +984,9 @@ describe( 'DataViews component', () => { // The checkbox click selects the third item and makes it the // anchor. await user.click( - screen.getByRole( 'checkbox', { name: data[ 2 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 2 ].title }`, + } ) ); // Shift-clicking the first item's checkbox selects the whole @@ -967,12 +995,16 @@ describe( 'DataViews component', () => { // toggle after React re-renders, leaving it visually unchecked. await user.keyboard( '{Shift>}' ); await user.click( - screen.getByRole( 'checkbox', { name: data[ 0 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 0 ].title }`, + } ) ); await user.keyboard( '{/Shift}' ); for ( const item of data ) { expect( - screen.getByRole( 'checkbox', { name: item.title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ item.title }`, + } ) ).toBeChecked(); } } ); @@ -1007,14 +1039,18 @@ describe( 'DataViews component', () => { await user.click( screen.getByText( data[ 1 ].title ) ); expect( onClickItem ).not.toHaveBeenCalled(); expect( - screen.getByRole( 'checkbox', { name: data[ 1 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 1 ].title }`, + } ) ).not.toBeChecked(); // Selectable items still respond and become the anchor. await user.click( screen.getByText( data[ 0 ].title ) ); await user.keyboard( '{/Control}' ); expect( - screen.getByRole( 'checkbox', { name: data[ 0 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 0 ].title }`, + } ) ).toBeChecked(); // Shift+Click ranges skip the non-selectable item. @@ -1022,13 +1058,19 @@ describe( 'DataViews component', () => { await user.click( screen.getByText( data[ 2 ].title ) ); await user.keyboard( '{/Shift}' ); expect( - screen.getByRole( 'checkbox', { name: data[ 0 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 0 ].title }`, + } ) ).toBeChecked(); expect( - screen.getByRole( 'checkbox', { name: data[ 1 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 1 ].title }`, + } ) ).not.toBeChecked(); expect( - screen.getByRole( 'checkbox', { name: data[ 2 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 2 ].title }`, + } ) ).toBeChecked(); expect( onClickItem ).not.toHaveBeenCalled(); } ); @@ -1065,10 +1107,14 @@ describe( 'DataViews component', () => { ); const user = userEvent.setup(); await user.click( - screen.getByRole( 'checkbox', { name: data[ 0 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 0 ].title }`, + } ) ); await user.click( - screen.getByRole( 'checkbox', { name: data[ 1 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 1 ].title }`, + } ) ); await user.click( @@ -1233,7 +1279,7 @@ describe( 'DataViews component', () => { /> ); const firstCheckbox = screen.getByRole( 'checkbox', { - name: data[ 0 ].title, + name: `Select ${ data[ 0 ].title }`, } ); const user = userEvent.setup(); await user.click( firstCheckbox ); @@ -1241,7 +1287,7 @@ describe( 'DataViews component', () => { // First item should be selected. expect( firstCheckbox ).toBeChecked(); const thirdCheckbox = screen.getByRole( 'checkbox', { - name: data[ 2 ].title, + name: `Select ${ data[ 2 ].title }`, } ); await user.click( thirdCheckbox ); @@ -1275,7 +1321,9 @@ describe( 'DataViews component', () => { // First item should be selected. expect( - screen.getByRole( 'checkbox', { name: data[ 0 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 0 ].title }`, + } ) ).toBeChecked(); await user.keyboard( '{/Control}' ); @@ -1304,7 +1352,9 @@ describe( 'DataViews component', () => { ); await user.keyboard( '{/Control}' ); expect( - screen.getByRole( 'checkbox', { name: data[ 0 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 0 ].title }`, + } ) ).toBeChecked(); // Shift+Click selects everything between the anchor and the @@ -1316,7 +1366,9 @@ describe( 'DataViews component', () => { await user.keyboard( '{/Shift}' ); for ( const item of data ) { expect( - screen.getByRole( 'checkbox', { name: item.title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ item.title }`, + } ) ).toBeChecked(); } } ); @@ -1358,7 +1410,9 @@ describe( 'DataViews component', () => { await user.tab(); expect( - screen.getByRole( 'checkbox', { name: data[ 0 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 0 ].title }`, + } ) ).toHaveFocus(); await user.tab(); @@ -1407,7 +1461,9 @@ describe( 'DataViews component', () => { await user.tab(); expect( - screen.getByRole( 'checkbox', { name: data[ 0 ].title } ) + screen.getByRole( 'checkbox', { + name: `Select ${ data[ 0 ].title }`, + } ) ).toHaveFocus(); await user.tab(); From c03f0366d29cf721aa5e8163e7dde62581a32536 Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 09:14:58 +0530 Subject: [PATCH 02/26] DataViews: Announce when bulk actions become available or unavailable --- packages/dataviews/src/dataviews/index.tsx | 25 +++++++++++ .../dataviews/test/dataviews.jsdom.test.tsx | 43 +++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/packages/dataviews/src/dataviews/index.tsx b/packages/dataviews/src/dataviews/index.tsx index 527bebdb04f4b3..3ef17d1343a628 100644 --- a/packages/dataviews/src/dataviews/index.tsx +++ b/packages/dataviews/src/dataviews/index.tsx @@ -8,6 +8,9 @@ import { } from '@wordpress/element'; import { Stack, useEnableWpCompatOverlaySlot } from '@wordpress/ui'; import deprecated from '@wordpress/deprecated'; +import { speak } from '@wordpress/a11y'; +import { __ } from '@wordpress/i18n'; +import { hasAPossibleBulkAction } from '../components/dataviews-bulk-actions'; import DataViewsContext from '../components/dataviews-context'; import { VIEW_LAYOUTS } from '../components/dataviews-layouts'; import { @@ -139,9 +142,31 @@ function DataViews< Item >( { const containerRef = useRef< HTMLDivElement >( null ); const [ containerWidth, resizeObserverRef ] = useContainerWidth(); const [ openedFilter, setOpenedFilter ] = useState< string | null >( null ); + function hasBulkActionsFor( ids: string[] ) { + return data.some( + ( item ) => + ids.includes( getItemId( item ) ) && + hasAPossibleBulkAction( actions, item ) + ); + } function setSelectionWithChange( value: SelectionOrUpdater ) { const newValue = typeof value === 'function' ? value( selection ) : value; + // The bulk actions only show once an item is selected, so screen + // reader users can't find them beforehand. Say when selecting makes + // them available and when clearing the selection removes them. Only + // changes made here, by the user, are announced: when the consumer + // clears the selection, e.g. after moving the items to the trash, + // announcing it would cut off the notice of that action. + const hadBulkActions = hasBulkActionsFor( selection ); + const hasBulkActions = hasBulkActionsFor( newValue ); + if ( hadBulkActions !== hasBulkActions ) { + speak( + hasBulkActions + ? __( 'Bulk actions available.' ) + : __( 'Bulk actions no longer available.' ) + ); + } if ( isUncontrolled ) { setSelectionState( newValue ); } diff --git a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx index b1f49c98ba836e..1f30b0dc03289c 100644 --- a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx +++ b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx @@ -1,6 +1,7 @@ import { render, screen, waitFor, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { speak } from '@wordpress/a11y'; import { useMemo, useState } from '@wordpress/element'; import DataViews from '../index'; import { @@ -174,6 +175,8 @@ vi.mock( import( '@wordpress/compose' ), async ( importOriginal ) => { } as unknown as typeof original; } ); +vi.mock( import( '@wordpress/a11y' ), () => ( { speak: vi.fn() } ) as any ); + describe( 'DataViews component', () => { it.each( [ 'Delete', 'Delete……' ] )( 'uses button and item-menu labels for modal action "%s"', @@ -305,6 +308,46 @@ describe( 'DataViews component', () => { expect( within( titleHeader ).getByRole( 'button' ) ).toBeEnabled(); } ); + it( 'announces when selecting makes bulk actions available or unavailable', async () => { + vi.mocked( speak ).mockClear(); + render( + + ); + const user = userEvent.setup(); + await user.click( + screen.getByRole( 'checkbox', { name: 'Select Hello World' } ) + ); + expect( speak ).toHaveBeenLastCalledWith( 'Bulk actions available.' ); + await user.click( + screen.getByRole( 'checkbox', { name: 'Select Homepage' } ) + ); + expect( speak ).toHaveBeenCalledTimes( 1 ); + await user.click( + screen.getByRole( 'checkbox', { name: 'Select Hello World' } ) + ); + expect( speak ).toHaveBeenCalledTimes( 1 ); + await user.click( + screen.getByRole( 'checkbox', { name: 'Select Homepage' } ) + ); + expect( speak ).toHaveBeenLastCalledWith( + 'Bulk actions no longer available.' + ); + expect( speak ).toHaveBeenCalledTimes( 2 ); + } ); + + it( 'does not announce bulk actions when the consumer clears the selection', () => { + vi.mocked( speak ).mockClear(); + const props = { onChangeSelection: vi.fn(), actions }; + const { rerender } = render( + + ); + rerender( ); + expect( speak ).not.toHaveBeenCalled(); + } ); + it( 'disabled desktop bulk action cannot run', async () => { const callback = vi.fn(); render( From ceb80d8a8ea2ae2cb8d24d7b790400bc17d75b8b Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 09:16:58 +0530 Subject: [PATCH 03/26] DataViews: Keep focus in the layout when the focused control is removed --- .../src/components/dataviews-layout/index.tsx | 5 +- .../test/bulk-selection.browser.test.tsx | 67 ++++++++++++++++ .../dataviews/src/hooks/use-focus-fallback.ts | 77 +++++++++++++++++++ 3 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 packages/dataviews/src/hooks/use-focus-fallback.ts diff --git a/packages/dataviews/src/components/dataviews-layout/index.tsx b/packages/dataviews/src/components/dataviews-layout/index.tsx index 1de3c484661f0a..22962f934a002b 100644 --- a/packages/dataviews/src/components/dataviews-layout/index.tsx +++ b/packages/dataviews/src/components/dataviews-layout/index.tsx @@ -1,10 +1,12 @@ import type { ComponentType } from 'react'; import { useContext } from '@wordpress/element'; import { Spinner as WCSpinner } from '@wordpress/components'; +import { useMergeRefs } from '@wordpress/compose'; import { __ } from '@wordpress/i18n'; import DataViewsContext from '../dataviews-context'; import { VIEW_LAYOUTS } from '../dataviews-layouts'; import { useDelayedLoading } from '../../hooks/use-delayed-loading'; +import useFocusFallback from '../../hooks/use-focus-fallback'; import type { ViewBaseProps } from '../../types'; type DataViewsLayoutProps = { @@ -33,6 +35,7 @@ export default function DataViewsLayout( { className }: DataViewsLayoutProps ) { empty =

{ __( 'No results' ) }

, } = useContext( DataViewsContext ); + const layoutRef = useMergeRefs( [ containerRef, useFocusFallback() ] ); const isDelayedInitialLoading = useDelayedLoading( ! hasInitiallyLoaded, { delay: 200, } ); @@ -59,7 +62,7 @@ export default function DataViewsLayout( { className }: DataViewsLayoutProps ) { )?.component as ComponentType< ViewBaseProps< any > >; return ( -
+
( { + type: 'table', + titleField: 'title', + fields: [ 'author' ], + page: 1, + perPage: 10, + } ); + const { data, paginationInfo } = filterSortAndPaginate( + items, + view, + fields + ); + const trashAction: Action< Post > = { + id: 'trash', + label: 'Trash', + isPrimary: true, + supportsBulk: true, + RenderModal: ( { items: itemsToTrash, closeModal } ) => ( + + ), + }; + return ( + + ); +} + +it( 'moves focus to the select all checkbox when an action removes the item that held it', async () => { + const user = userEvent.setup(); + await render( ); + await user.click( + page + .getByRole( 'row', { name: /First post/ } ) + .getByRole( 'button', { name: 'Trash', exact: true } ) + ); + await user.click( + page.getByRole( 'button', { name: 'Confirm', exact: true } ) + ); + await expect + .element( page.getByRole( 'row', { name: /First post/ } ) ) + .not.toBeInTheDocument(); + await expect + .element( + page.getByRole( 'checkbox', { name: 'Select all', exact: true } ) + ) + .toHaveFocus(); +} ); diff --git a/packages/dataviews/src/hooks/use-focus-fallback.ts b/packages/dataviews/src/hooks/use-focus-fallback.ts new file mode 100644 index 00000000000000..b98b1eb5f2f8d9 --- /dev/null +++ b/packages/dataviews/src/hooks/use-focus-fallback.ts @@ -0,0 +1,77 @@ +import { useRefEffect } from '@wordpress/compose'; + +const FOCUSABLE_SELECTOR = [ + 'button:not([disabled])', + 'input:not([disabled])', + 'a[href]', + '[tabindex="0"]', + '[role="checkbox"]:not([aria-disabled="true"])', +].join( ',' ); + +function isVisible( element: Element ) { + return element.getClientRects().length > 0; +} + +/** + * The control to focus when focus is lost: the first checkbox, which is the + * "Select all" one where the layout has it, or else the first control. + * + * @param container The layout container. + */ +function getFallback( container: HTMLElement ) { + const controls = Array.from( + container.querySelectorAll< HTMLElement >( FOCUSABLE_SELECTOR ) + ).filter( ( element ) => element.tabIndex >= 0 && isVisible( element ) ); + return ( + controls.find( + ( element ) => + element.getAttribute( 'role' ) === 'checkbox' || + ( element as HTMLInputElement ).type === 'checkbox' + ) ?? controls[ 0 ] + ); +} + +/** + * Keeps focus in the layout when the focused control goes away, e.g. when an + * action removes the item whose row held it, or the control a modal returns + * focus to is gone by the time the modal closes. Without this, focus falls + * back to the document body and keyboard users have to start over from the + * top of the page. + */ +export default function useFocusFallback() { + return useRefEffect( ( container: HTMLElement ) => { + const { ownerDocument } = container; + let lastFocused: HTMLElement | null = null; + const onFocusIn = ( event: FocusEvent ) => { + lastFocused = event.target as HTMLElement; + }; + const observer = new MutationObserver( () => { + if ( ! lastFocused ) { + return; + } + const { activeElement } = ownerDocument; + const wasRemoved = + ! lastFocused.isConnected || ! isVisible( lastFocused ); + const isLost = + ! activeElement || + activeElement === ownerDocument.body || + ( activeElement === lastFocused && wasRemoved ); + if ( ! wasRemoved || ! isLost ) { + return; + } + lastFocused = null; + getFallback( container )?.focus(); + } ); + container.addEventListener( 'focusin', onFocusIn ); + observer.observe( container, { + childList: true, + subtree: true, + attributes: true, + attributeFilter: [ 'hidden', 'inert' ], + } ); + return () => { + container.removeEventListener( 'focusin', onFocusIn ); + observer.disconnect(); + }; + }, [] ); +} From 156d6c792591c438275e849484efb3146da12d24 Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 09:18:17 +0530 Subject: [PATCH 04/26] DataViews: Mark the triggers of actions that open a dialog --- packages/dataviews/README.md | 8 +++++ .../dataviews-bulk-actions/index.tsx | 3 ++ .../dataviews-item-actions/index.tsx | 8 ++++- .../dataviews-layouts/list/index.tsx | 3 ++ .../dataviews/test/dataviews.jsdom.test.tsx | 33 +++++++++++++++++++ packages/dataviews/src/types/dataviews.ts | 6 ++++ .../dataviews/src/utils/get-action-popup.ts | 13 ++++++++ .../src/components/dataviews-actions/index.js | 1 + routes/post-list/stage.tsx | 1 + 9 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 packages/dataviews/src/utils/get-action-popup.ts diff --git a/packages/dataviews/README.md b/packages/dataviews/README.md index 053d458657b15a..7c9001983b2b42 100644 --- a/packages/dataviews/README.md +++ b/packages/dataviews/README.md @@ -1177,6 +1177,14 @@ Function that performs the required action. } ``` +### `opensDialog` + +Whether the `callback` opens a dialog, such as a modal. The trigger then has `aria-haspopup="dialog"`, as the triggers of `RenderModal` actions do. + +- Type: `boolean` +- Optional +- Default: `false` + ### `RenderModal` Component to render UI in a modal for the action. diff --git a/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx b/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx index 541ab5f95af0fe..5e1673c92ffe23 100644 --- a/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx +++ b/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx @@ -18,6 +18,7 @@ import type { SetSelection } from '../../types/private'; import type { ActionTriggerProps } from '../dataviews-item-actions'; import getFooterMessage from '../../utils/get-footer-message'; import getActionLabel from '../../utils/get-action-label'; +import getActionPopup from '../../utils/get-action-popup'; export function hasAPossibleBulkAction< Item >( actions: Action< Item >[], @@ -157,6 +158,7 @@ function ActionTrigger< Item >( { icon={ isMobile ? action.icon : undefined } size="compact" onClick={ onClick } + aria-haspopup={ getActionPopup( action ) } isBusy={ isBusy } > { ! isMobile && label } @@ -189,6 +191,7 @@ function ActionButton< Item >( { { getActionLabel( action, selectedEligibleItems, 'menu' ) } diff --git a/packages/dataviews/src/components/dataviews-item-actions/index.tsx b/packages/dataviews/src/components/dataviews-item-actions/index.tsx index 96ff74001983f8..7ac0ac7e4bb264 100644 --- a/packages/dataviews/src/components/dataviews-item-actions/index.tsx +++ b/packages/dataviews/src/components/dataviews-item-actions/index.tsx @@ -13,6 +13,7 @@ import { import { kebabCase } from '@wordpress/kebab-case'; import type { Action, ActionModal as ActionModalType } from '../../types'; import getActionLabel from '../../utils/get-action-label'; +import getActionPopup from '../../utils/get-action-popup'; export interface ActionTriggerProps< Item > { action: Action< Item >; @@ -69,6 +70,7 @@ function ButtonTrigger< Item >( { size="compact" variant={ variant } onClick={ onClick } + aria-haspopup={ getActionPopup( action ) } > { label } @@ -82,7 +84,11 @@ function MenuItemTrigger< Item >( { }: ActionTriggerProps< Item > ) { const label = getActionLabel( action, items, 'menu' ); return ( - + { label } ); diff --git a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx index e599a539d81d20..3ad63daca92062 100644 --- a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx @@ -33,6 +33,7 @@ import getDataByGroup from '../utils/get-data-by-group'; import useSelectionProps from '../utils/use-selection-props'; import type { SelectionProps } from '../utils/use-selection-props'; import getActionLabel from '../../../utils/get-action-label'; +import getActionPopup from '../../../utils/get-action-popup'; interface ListViewItemProps< Item > { view: ViewListType; @@ -91,6 +92,7 @@ function PrimaryActionGridCell< Item >( { accessibleWhenDisabled text={ label } size="small" + aria-haspopup="dialog" onClick={ () => setIsModalOpen( true ) } /> } @@ -113,6 +115,7 @@ function PrimaryActionGridCell< Item >( { disabled={ !! primaryAction.disabled } accessibleWhenDisabled size="small" + aria-haspopup={ getActionPopup( primaryAction ) } onClick={ () => { primaryAction.callback( [ item ], { registry } ); } } diff --git a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx index 1f30b0dc03289c..1319238569ab8b 100644 --- a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx +++ b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx @@ -205,6 +205,39 @@ describe( 'DataViews component', () => { } ); + it( 'marks the triggers of actions that open a dialog', async () => { + render( + + ); + expect( + screen.getByRole( 'button', { name: 'Delete' } ) + ).toHaveAttribute( 'aria-haspopup', 'dialog' ); + expect( + screen.getByRole( 'button', { name: 'Quick edit' } ) + ).toHaveAttribute( 'aria-haspopup', 'dialog' ); + const user = userEvent.setup(); + await user.click( screen.getByRole( 'button', { name: 'Actions' } ) ); + expect( + await screen.findByRole( 'menuitem', { name: 'View' } ) + ).not.toHaveAttribute( 'aria-haspopup' ); + expect( + screen.getByRole( 'menuitem', { name: 'Delete…' } ) + ).toHaveAttribute( 'aria-haspopup', 'dialog' ); + } ); + it( 'renders header bulk actions once in a custom table composition', () => { render( extends ActionBase< Item > { onActionPerformed?: ( items: Item[] ) => void; } ) => void; + + /** + * Whether the callback opens a dialog, such as a modal, so the trigger + * can tell assistive technologies. + */ + opensDialog?: boolean; } export type Action< Item > = ActionModal< Item > | ActionButton< Item >; diff --git a/packages/dataviews/src/utils/get-action-popup.ts b/packages/dataviews/src/utils/get-action-popup.ts new file mode 100644 index 00000000000000..01184ba9d68094 --- /dev/null +++ b/packages/dataviews/src/utils/get-action-popup.ts @@ -0,0 +1,13 @@ +import type { Action } from '../types'; + +/** + * The `aria-haspopup` value of an action's trigger: `dialog` when the action + * opens one, either its own modal or one its callback opens. + * + * @param action The action. + */ +export default function getActionPopup< Item >( action: Action< Item > ) { + return 'RenderModal' in action || action.opensDialog + ? ( 'dialog' as const ) + : undefined; +} diff --git a/packages/edit-site/src/components/dataviews-actions/index.js b/packages/edit-site/src/components/dataviews-actions/index.js index 92448bb910360c..c2a089613fbb9b 100644 --- a/packages/edit-site/src/components/dataviews-actions/index.js +++ b/packages/edit-site/src/components/dataviews-actions/index.js @@ -42,6 +42,7 @@ export const useQuickEditPostAction = () => { icon: drawerRight, isPrimary: true, supportsBulk: true, + opensDialog: true, isEligible( post ) { if ( post.status === 'trash' ) { return false; diff --git a/routes/post-list/stage.tsx b/routes/post-list/stage.tsx index 3063b8ff69705b..0fcbc6e79eb24d 100644 --- a/routes/post-list/stage.tsx +++ b/routes/post-list/stage.tsx @@ -252,6 +252,7 @@ function PostListView( { icon: drawerRight, isPrimary: true, supportsBulk: true, + opensDialog: true, isEligible( post: Post ) { // PostStatus only includes assignable statuses. 'trash' is managed // internally by WordPress, but the REST API can still return it. From 9e29f1f12a580d374ba34e0909d91755a5a7c339 Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 09:19:24 +0530 Subject: [PATCH 05/26] Fields: Hide decorative author avatars from assistive technologies --- packages/core-fields/src/attachment/author/view.tsx | 4 ++-- packages/core-fields/src/post_type_supports/author/view.tsx | 4 ++-- .../src/components/post-revisions-timeline/author-field.tsx | 3 ++- packages/media-fields/src/author/view.tsx | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/core-fields/src/attachment/author/view.tsx b/packages/core-fields/src/attachment/author/view.tsx index 7801f33b0dbf29..063af07337719b 100644 --- a/packages/core-fields/src/attachment/author/view.tsx +++ b/packages/core-fields/src/attachment/author/view.tsx @@ -1,5 +1,4 @@ import clsx from 'clsx'; -import { __ } from '@wordpress/i18n'; import { useState, useCallback, useEffect } from '@wordpress/element'; import { commentAuthorAvatar as authorIcon } from '@wordpress/icons'; import { Icon, Stack } from '@wordpress/ui'; @@ -52,7 +51,8 @@ export default function AuthorView( { item }: { item: MediaItem } ) { {
diff --git a/packages/core-fields/src/post_type_supports/author/view.tsx b/packages/core-fields/src/post_type_supports/author/view.tsx index 227ad6cb25376e..e1bda67c06575e 100644 --- a/packages/core-fields/src/post_type_supports/author/view.tsx +++ b/packages/core-fields/src/post_type_supports/author/view.tsx @@ -1,5 +1,4 @@ import clsx from 'clsx'; -import { __ } from '@wordpress/i18n'; import { useState } from '@wordpress/element'; import { commentAuthorAvatar as authorIcon } from '@wordpress/icons'; import { Icon, Stack } from '@wordpress/ui'; @@ -62,7 +61,8 @@ export default function AuthorView( { item }: { item: PostWithAuthor } ) { > setIsImageLoaded( true ) } - alt={ __( 'Author avatar' ) } + // Decorative: the name of the author is next to it. + alt="" src={ imageUrl } />
diff --git a/packages/editor/src/components/post-revisions-timeline/author-field.tsx b/packages/editor/src/components/post-revisions-timeline/author-field.tsx index 636438c39dc8a3..f0aa4ae5c73f05 100644 --- a/packages/editor/src/components/post-revisions-timeline/author-field.tsx +++ b/packages/editor/src/components/post-revisions-timeline/author-field.tsx @@ -57,7 +57,8 @@ function AuthorView( { item }: { item: BasePostWithEmbeddedAuthor } ) { > setIsImageLoaded( true ) } - alt={ __( 'Author avatar' ) } + // Decorative: the name of the author is next to it. + alt="" src={ imageUrl } /> diff --git a/packages/media-fields/src/author/view.tsx b/packages/media-fields/src/author/view.tsx index ad8844b238f76d..733e8e6946c8d7 100644 --- a/packages/media-fields/src/author/view.tsx +++ b/packages/media-fields/src/author/view.tsx @@ -1,5 +1,4 @@ import clsx from 'clsx'; -import { __ } from '@wordpress/i18n'; import { useState, useCallback, useEffect } from '@wordpress/element'; import { commentAuthorAvatar as authorIcon } from '@wordpress/icons'; import { @@ -52,7 +51,8 @@ export default function AuthorView( { { From f39ae01c81549e9e9e68022013f9eeb88c0fc44c Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 09:21:55 +0530 Subject: [PATCH 06/26] Boot: Only announce the route title when the path changes --- package-lock.json | 3 ++ packages/boot/package.json | 3 ++ .../app/test/use-route-title.jsdom.test.ts | 45 +++++++++++++++++++ .../src/components/app/use-route-title.ts | 10 +++-- 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 packages/boot/src/components/app/test/use-route-title.jsdom.test.ts diff --git a/package-lock.json b/package-lock.json index 22861e8ffe81c7..1f5f9828511829 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44838,6 +44838,9 @@ "@wordpress/url": "file:../url", "clsx": "^2.1.1" }, + "devDependencies": { + "@testing-library/react": "^16.3.3" + }, "engines": { "node": ">=22.13.0" }, diff --git a/packages/boot/package.json b/packages/boot/package.json index 29859b87aeed9a..0eeb46b94c3c88 100644 --- a/packages/boot/package.json +++ b/packages/boot/package.json @@ -66,6 +66,9 @@ "@wordpress/url": "file:../url", "clsx": "^2.1.1" }, + "devDependencies": { + "@testing-library/react": "^16.3.3" + }, "peerDependencies": { "@types/react": "^18 || ^19", "react": "^18 || ^19", diff --git a/packages/boot/src/components/app/test/use-route-title.jsdom.test.ts b/packages/boot/src/components/app/test/use-route-title.jsdom.test.ts new file mode 100644 index 00000000000000..56916223e5fb96 --- /dev/null +++ b/packages/boot/src/components/app/test/use-route-title.jsdom.test.ts @@ -0,0 +1,45 @@ +import { renderHook } from '@testing-library/react'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { speak } from '@wordpress/a11y'; +import useRouteTitle from '../use-route-title'; + +let location: { pathname: string; search: Record< string, unknown > }; + +vi.mock( import( '@wordpress/a11y' ), () => ( { speak: vi.fn() } ) as any ); +vi.mock( import( '@wordpress/data' ), async ( importOriginal ) => ( { + ...( await importOriginal() ), + useSelect: ( () => 'My Site' ) as any, +} ) ); +vi.mock( + import( '../../../lock-unlock' ), + () => + ( { + unlock: () => ( { + useLocation: () => location, + useMatches: () => [ { loaderData: { title: 'Pages' } } ], + } ), + } ) as any +); + +describe( 'useRouteTitle', () => { + beforeEach( () => { + vi.mocked( speak ).mockClear(); + location = { pathname: '/types/page/list/all', search: {} }; + } ); + + it( 'announces the title when the path changes', () => { + const { rerender } = renderHook( () => useRouteTitle() ); + vi.mocked( speak ).mockClear(); + location = { ...location, pathname: '/types/page/list/draft' }; + rerender(); + expect( speak ).toHaveBeenCalledWith( 'Pages', 'assertive' ); + } ); + + it( 'does not announce the title when only the search changes', () => { + const { rerender } = renderHook( () => useRouteTitle() ); + vi.mocked( speak ).mockClear(); + location = { ...location, search: { postIds: [ '1' ] } }; + rerender(); + expect( speak ).not.toHaveBeenCalled(); + } ); +} ); diff --git a/packages/boot/src/components/app/use-route-title.ts b/packages/boot/src/components/app/use-route-title.ts index 26c27a13f96ba2..40597f802d953f 100644 --- a/packages/boot/src/components/app/use-route-title.ts +++ b/packages/boot/src/components/app/use-route-title.ts @@ -16,7 +16,11 @@ const { useLocation, useMatches } = unlock( routePrivateApis ); * This hook should be called from the Root component to ensure it runs on every route. */ export default function useRouteTitle() { - const location = useLocation(); + // Only a new path is a new screen. Search parameters also change while the + // screen stays, e.g. when the selection changes or an item is moved to the + // trash, and announcing the title then would clear the live regions and cut + // off the notice of what happened. + const { pathname } = useLocation(); const matches = useMatches(); const currentMatch = matches[ matches.length - 1 ]; const routeTitle = ( currentMatch?.loaderData as any )?.title as @@ -35,7 +39,7 @@ export default function useRouteTitle() { useEffect( () => { isInitialLocationRef.current = false; - }, [ location ] ); + }, [ pathname ] ); useEffect( () => { // Don't update or announce the title for initial page load. @@ -68,5 +72,5 @@ export default function useRouteTitle() { speak( decodedRouteTitle, 'assertive' ); } } - }, [ routeTitle, siteTitle, location ] ); + }, [ routeTitle, siteTitle, pathname ] ); } From d834029cce8d284ba0c78f3e27d1b41091fce246 Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 09:23:36 +0530 Subject: [PATCH 07/26] DataViews: Replace the Cancel icon of the bulk actions with a Clear selection button --- .../components/dataviews-bulk-actions/index.tsx | 14 ++++++++------ .../components/dataviews-bulk-actions/style.scss | 4 ---- .../test/bulk-selection.browser.test.tsx | 15 ++++++++++----- .../src/dataviews/test/dataviews.jsdom.test.tsx | 6 ++++-- test/e2e/specs/site-editor/page-list.spec.js | 4 +++- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx b/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx index 5e1673c92ffe23..a446ea01d024c9 100644 --- a/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx +++ b/packages/dataviews/src/components/dataviews-bulk-actions/index.tsx @@ -2,7 +2,7 @@ import { Button } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { useMemo, useState, useContext } from '@wordpress/element'; import { useRegistry } from '@wordpress/data'; -import { closeSmall, chevronDown } from '@wordpress/icons'; +import { chevronDown } from '@wordpress/icons'; import { useViewportMatch } from '@wordpress/compose'; import { Checkbox, @@ -224,18 +224,20 @@ function renderBulkActionsContent< Item >( isMobile: boolean, selectionCheckboxRef?: React.Ref< HTMLSpanElement > ) { + // A text button next to the actions, rather than a close icon at the far + // end, so it can't be read as closing the whole view and stays in sight + // for screen magnifier users. const clearSelection = selectedItems.length > 0 && ( ); const renderActions = ( isMenuItem = false ) => actionsToShow.map( ( action ) => ( diff --git a/packages/dataviews/src/components/dataviews-bulk-actions/style.scss b/packages/dataviews/src/components/dataviews-bulk-actions/style.scss index aa6e5b25e07b7d..fc7370f43bdc71 100644 --- a/packages/dataviews/src/components/dataviews-bulk-actions/style.scss +++ b/packages/dataviews/src/components/dataviews-bulk-actions/style.scss @@ -10,10 +10,6 @@ border-bottom: var(--wpds-border-width-xs) solid var(--wpds-color-stroke-surface-neutral-weak); } -.dataviews-bulk-actions__clear { - margin-inline-start: auto; -} - .dataviews-bulk-actions__action { --wp-components-color-accent: var(--wpds-color-foreground-interactive-neutral); --wp-components-color-accent-darker-20: var(--wpds-color-foreground-interactive-neutral-active); diff --git a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx index c2f67c988052af..ac70cff39f4b21 100644 --- a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx +++ b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx @@ -95,10 +95,12 @@ it( 'keeps column names and sorting accessible during selection, skips covered c .toHaveFocus(); await user.keyboard( '{Tab}' ); await expect - .element( page.getByRole( 'button', { name: 'Cancel', exact: true } ) ) + .element( + page.getByRole( 'button', { name: 'Clear selection', exact: true } ) + ) .toHaveFocus(); await user.click( - page.getByRole( 'button', { name: 'Cancel', exact: true } ) + page.getByRole( 'button', { name: 'Clear selection', exact: true } ) ); await expect @@ -133,7 +135,7 @@ it( 'blocks focus on bulk actions and covers column headings while loading', asy page.getByRole( 'checkbox', { name: 'Select all', exact: true } ) ); const cancel = page - .getByRole( 'button', { name: 'Cancel', exact: true } ) + .getByRole( 'button', { name: 'Clear selection', exact: true } ) .element(); const table = page.getByRole( 'table' ).element(); const toolbar = document.querySelector( '.dataviews-bulk-actions' )!; @@ -243,7 +245,10 @@ it.each( [ 'balanced', 'compact', 'comfortable' ] as const )( ).toBeLessThanOrEqual( 0.5 ); await expect .element( - page.getByRole( 'button', { name: 'Cancel', exact: true } ) + page.getByRole( 'button', { + name: 'Clear selection', + exact: true, + } ) ) .toBeInViewport(); } @@ -254,7 +259,7 @@ it.each( [ 'balanced', 'compact', 'comfortable' ] as const )( .poll( () => toolbar.getBoundingClientRect().height ) .toBe( 96 ); await user.click( - page.getByRole( 'button', { name: 'Cancel', exact: true } ) + page.getByRole( 'button', { name: 'Clear selection', exact: true } ) ); await expect .element( diff --git a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx index 1319238569ab8b..aaad5e34095b22 100644 --- a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx +++ b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx @@ -275,7 +275,9 @@ describe( 'DataViews component', () => { expect( screen.getByRole( 'button', { name: 'Delete' } ) ).toBeInTheDocument(); - await user.click( screen.getByRole( 'button', { name: 'Cancel' } ) ); + await user.click( + screen.getByRole( 'button', { name: 'Clear selection' } ) + ); expect( screen.getByText( 'Select all' ) ).toBeVisible(); } ); @@ -439,7 +441,7 @@ describe( 'DataViews component', () => { ).toBeInTheDocument(); await user.click( - within( toolbar ).getByRole( 'button', { name: 'Cancel' } ) + within( toolbar ).getByRole( 'button', { name: 'Clear selection' } ) ); expect( within( titleHeader ).getByRole( 'button' ) ).toBeEnabled(); expect( diff --git a/test/e2e/specs/site-editor/page-list.spec.js b/test/e2e/specs/site-editor/page-list.spec.js index e539d2b26da2c6..a363b7dd54949c 100644 --- a/test/e2e/specs/site-editor/page-list.spec.js +++ b/test/e2e/specs/site-editor/page-list.spec.js @@ -649,7 +649,9 @@ test.describe( 'Page List', () => { toolbar.getByText( /items selected/ ) ).toBeInViewport( { ratio: 1 } ); await page.keyboard.press( 'Escape' ); - await toolbar.getByRole( 'button', { name: 'Cancel' } ).click(); + await toolbar + .getByRole( 'button', { name: 'Clear selection' } ) + .click(); await expect( page.getByRole( 'checkbox', { name: 'Select all', From 33f27d9b4b2d459624a4d328e25a992068f89ae3 Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 09:26:21 +0530 Subject: [PATCH 08/26] DataViews: Keep the table media out of the tab order next to a clickable title --- .../table/column-primary.tsx | 19 ++++++++----- .../dataviews-layouts/table/style.scss | 9 +++++++ .../utils/item-click-wrapper.tsx | 1 + .../dataviews/test/dataviews.jsdom.test.tsx | 27 +++++++++++++++++++ 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-layouts/table/column-primary.tsx b/packages/dataviews/src/components/dataviews-layouts/table/column-primary.tsx index 982c5eb87ca75b..09c2b71b3d7c62 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/column-primary.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/table/column-primary.tsx @@ -43,6 +43,14 @@ function ColumnPrimary< Item >( { Math.round( ( 32 * ratioWidth ) / ratioHeight ) ) }px`; } + // The title next to the media leads to the same place, so keep the media + // out of the tab order and the accessibility tree. Otherwise keyboard and + // screen reader users meet the same control twice, and the cell is read + // with the title repeated. + const isMediaRedundant = + isItemClickable( item ) && + ( !! onClickItem || !! renderItemLink ) && + !! titleField; return ( { mediaField && ( @@ -52,13 +60,10 @@ function ColumnPrimary< Item >( { onClickItem={ onClickItem } renderItemLink={ renderItemLink } className="dataviews-view-table__cell-content-wrapper dataviews-column-primary__media" - aria-label={ - isItemClickable( item ) && - ( !! onClickItem || !! renderItemLink ) && - !! titleField - ? titleField.getValue?.( { item } ) - : undefined - } + { ...( isMediaRedundant && { + tabIndex: -1, + 'aria-hidden': true, + } ) } > ( { ) => ReactElement; className?: string; title?: string; + tabIndex?: number; children: ReactNode; } ) { // Always render a wrapper element so layout and styling relying on the wrapper diff --git a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx index aaad5e34095b22..b759a7033d3e4b 100644 --- a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx +++ b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx @@ -813,6 +813,33 @@ describe( 'DataViews component', () => { } } ); + it( 'keeps clickable media next to a clickable title out of the tab order', () => { + render( + true } + onClickItem={ () => {} } + /> + ); + expect( + screen.getAllByRole( 'button', { name: data[ 0 ].title } ) + ).toHaveLength( 1 ); + const media = screen + .getAllByRole( 'button', { hidden: true } ) + .find( ( button ) => + button.classList.contains( + 'dataviews-column-primary__media' + ) + ); + expect( media ).toHaveAttribute( 'tabindex', '-1' ); + expect( media ).toHaveAttribute( 'aria-hidden', 'true' ); + } ); + it( 'should render actions column if actions are supported and passed in', () => { render( ); expect( screen.getByText( 'Actions' ) ).toBeInTheDocument(); From 21b103a829c42535019d4872aee550017cc61b3a Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 09:27:01 +0530 Subject: [PATCH 09/26] DataViews: Set the grid selection checkbox apart from the preview --- .../dataviews/src/components/dataviews-layouts/grid/style.scss | 3 +++ .../src/components/dataviews-layouts/picker-grid/style.scss | 2 ++ 2 files changed, 5 insertions(+) diff --git a/packages/dataviews/src/components/dataviews-layouts/grid/style.scss b/packages/dataviews/src/components/dataviews-layouts/grid/style.scss index 186fdc0044d1bd..3dd22c6b2c536f 100644 --- a/packages/dataviews/src/components/dataviews-layouts/grid/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/grid/style.scss @@ -212,6 +212,9 @@ // Ensure selection checkbox stays above the preview field. z-index: 1; opacity: 0; + // The preview can be any color, including the checkbox's own background + // or border. A ring in the surface color sets it apart from the preview. + box-shadow: 0 0 0 calc(2 * var(--wpds-border-width-xs)) var(--wpds-color-background-surface-neutral-strong); @media not (prefers-reduced-motion) { transition: opacity 0.1s linear; diff --git a/packages/dataviews/src/components/dataviews-layouts/picker-grid/style.scss b/packages/dataviews/src/components/dataviews-layouts/picker-grid/style.scss index 83a7b6d883da67..058ba855731d31 100644 --- a/packages/dataviews/src/components/dataviews-layouts/picker-grid/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/picker-grid/style.scss @@ -172,6 +172,8 @@ left: var(--wpds-dimension-padding-sm); // Ensure selection checkbox stays above the preview field. z-index: 1; + // Set the checkbox apart from previews of any color, as the grid does. + box-shadow: 0 0 0 calc(2 * var(--wpds-border-width-xs)) var(--wpds-color-background-surface-neutral-strong); @media (hover: none) { // Show checkboxes on devices that do not support hover. From ef0da6af86dfad426f426a1dbcf36fbde4d1e79e Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 09:28:20 +0530 Subject: [PATCH 10/26] Media Utils: Show that clicking the media preview replaces it --- .../src/components/media-edit/index.tsx | 13 ++++++ .../src/components/media-edit/style.scss | 13 ++++++ .../media-edit/test/index.jsdom.test.tsx | 40 ++++++++++++++++++- 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/packages/media-utils/src/components/media-edit/index.tsx b/packages/media-utils/src/components/media-edit/index.tsx index 1d6d781042424a..19f74a3ffb5d21 100644 --- a/packages/media-utils/src/components/media-edit/index.tsx +++ b/packages/media-utils/src/components/media-edit/index.tsx @@ -399,6 +399,19 @@ function ExpandedMediaEditAttachments( { { ! isBlob && (
+ { /* + * The preview replaces the media when clicked, + * but only the remove button shows on hover. Say + * so on the preview too. The preview's own label + * already names the action for assistive + * technologies. + */ } + [] | null, +} = {} ) { const registry = createRegistry(); registry.register( createReduxStore( 'core', { reducer: ( state = {} ) => state, selectors: { canUser: () => canUpload, - getEntityRecords: () => null, + getEntityRecords: () => attachments, }, actions: { receiveEntityRecords: () => ( { @@ -119,6 +122,39 @@ describe( 'MediaEdit', () => { ); } ); + it( 'shows that clicking the preview replaces the media', () => { + render( + + {} } + isExpanded + /> + + ); + expect( + screen.getByRole( 'button', { name: 'Replace Photo' } ) + ).toBeInTheDocument(); + // A visual hint only: the preview's label already names the action. + expect( screen.getByText( 'Replace' ) ).toHaveAttribute( + 'aria-hidden', + 'true' + ); + } ); + it( 'shows a message instead of the picker without upload permission', () => { render( Date: Mon, 2 Nov 2026 09:31:16 +0530 Subject: [PATCH 11/26] DataViews: Name list items by their title only --- .../dataviews-layouts/list/index.tsx | 4 ++++ .../dataviews/test/dataviews.jsdom.test.tsx | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx index 3ad63daca92062..47e01347a86bc3 100644 --- a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx @@ -286,6 +286,10 @@ function ListItem< Item >( { /> } role={ infiniteScrollEnabled ? 'article' : 'row' } + // Otherwise the row is named after all of its content: the title, + // the actions and every field. The fields stay available as the + // description of the item. + aria-labelledby={ labelId } className={ clsx( { 'is-selected': isSelected, 'is-hovered': isHovered, diff --git a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx index b759a7033d3e4b..5887e3af9c8c60 100644 --- a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx +++ b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx @@ -1708,6 +1708,25 @@ describe( 'DataViews component', () => { } } ); + it( 'names each item by its title and describes it by its fields', async () => { + render( + + ); + expect( + await screen.findByRole( 'row', { name: 'Hello World' } ) + ).toBeInTheDocument(); + expect( + screen.getByRole( 'button', { name: 'Hello World' } ) + ).toHaveAccessibleDescription( /Author\s*Jane/ ); + } ); + it( 'should render actions dropdown if actions are supported and passed in for each list item', async () => { render( Date: Mon, 2 Nov 2026 09:31:51 +0530 Subject: [PATCH 12/26] Add changelog entries --- packages/boot/CHANGELOG.md | 1 + packages/dataviews/CHANGELOG.md | 8 ++++++++ packages/media-fields/CHANGELOG.md | 4 ++++ packages/media-utils/CHANGELOG.md | 1 + 4 files changed, 14 insertions(+) diff --git a/packages/boot/CHANGELOG.md b/packages/boot/CHANGELOG.md index 458a902be92ad6..65fa80dcb3523f 100644 --- a/packages/boot/CHANGELOG.md +++ b/packages/boot/CHANGELOG.md @@ -8,6 +8,7 @@ ### Bug Fixes +- Only announce the route title when the path changes, so it no longer cuts off notices, such as the one confirming that an item was moved to the trash ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). - Generated CSS module class names now change whenever their CSS changes, so they differ from earlier versions. Two versions of the package loaded on the same page, such as one in WordPress Core and an older copy bundled in a plugin, no longer apply their styles to each other's elements ([#85900](https://github.com/WordPress/gutenberg/pull/85900)). ## 0.25.0 (2026-10-20) diff --git a/packages/dataviews/CHANGELOG.md b/packages/dataviews/CHANGELOG.md index 11c746846fc3cb..14b3e741c417fe 100644 --- a/packages/dataviews/CHANGELOG.md +++ b/packages/dataviews/CHANGELOG.md @@ -9,6 +9,8 @@ ### Enhancements +- Add `opensDialog` for actions whose `callback` opens a dialog. The triggers of these actions and of `RenderModal` actions now have `aria-haspopup="dialog"` ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). +- Replace the close icon that cancels the selection with a "Clear selection" button next to the bulk actions ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). - DataForm: Tighten the line height of field values in the panel layout, so values that wrap onto several lines take less room ([#85828](https://github.com/WordPress/gutenberg/pull/85828)). - Omit trailing ellipses from action button labels ([#85396](https://github.com/WordPress/gutenberg/pull/85396)). - Render table bulk actions outside the table while preserving their placement over the column headers ([#85250](https://github.com/WordPress/gutenberg/pull/85250)). @@ -19,6 +21,12 @@ ### Bug Fixes +- Name the action in the labels of selection checkboxes: "Select [title]" ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). +- Announce when selecting items makes bulk actions available and when clearing the selection removes them ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). +- Move focus to the "Select all" checkbox, or the first control of the layout, when the focused control is removed, such as after moving an item to the trash ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). +- Keep the table media out of the tab order and the accessibility tree when the title next to it leads to the same place, and show a focus ring on it otherwise ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). +- Name list items by their title only, not by all of their content ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). +- Set the grid selection checkbox apart from previews of any color ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). - DataForm: Keep the first line of a panel field label that wraps level with its value ([#85828](https://github.com/WordPress/gutenberg/pull/85828)). - Replace the pagination page select with a page number input above 100 pages, so a dataset with tens of thousands of pages no longer freezes the browser ([#85303](https://github.com/WordPress/gutenberg/pull/85303)). diff --git a/packages/media-fields/CHANGELOG.md b/packages/media-fields/CHANGELOG.md index e08f919b1c8800..1b7ab3a9a9c457 100644 --- a/packages/media-fields/CHANGELOG.md +++ b/packages/media-fields/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Bug Fixes + +- Hide the decorative author avatar from assistive technologies, as the name of the author is next to it ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). + ## 0.23.0 (2026-10-20) ### Breaking Changes diff --git a/packages/media-utils/CHANGELOG.md b/packages/media-utils/CHANGELOG.md index 42e05b7941eae7..5147e5769092f8 100644 --- a/packages/media-utils/CHANGELOG.md +++ b/packages/media-utils/CHANGELOG.md @@ -4,6 +4,7 @@ ### Enhancements +- `MediaEdit`: Show that clicking the preview of a media item replaces it ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). - `MediaEdit`: Use design system's outline focus ring instead of previous box-shadow based implementation & only animate on items reorder. ([#84940](https://github.com/WordPress/gutenberg/pull/84940)). ## 6.0.0 (2026-10-20) From ce9b9d1939d3684af76dc428d22604d0a5153308 Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 09:35:39 +0530 Subject: [PATCH 13/26] Boot: Declare the test dependencies --- package-lock.json | 3 ++- packages/boot/package.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1f5f9828511829..ec9b918f6f793d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44839,7 +44839,8 @@ "clsx": "^2.1.1" }, "devDependencies": { - "@testing-library/react": "^16.3.3" + "@testing-library/react": "^16.3.3", + "vitest": "^5.0.3" }, "engines": { "node": ">=22.13.0" diff --git a/packages/boot/package.json b/packages/boot/package.json index 0eeb46b94c3c88..ac9dd1bde82e34 100644 --- a/packages/boot/package.json +++ b/packages/boot/package.json @@ -67,7 +67,8 @@ "clsx": "^2.1.1" }, "devDependencies": { - "@testing-library/react": "^16.3.3" + "@testing-library/react": "^16.3.3", + "vitest": "^5.0.3" }, "peerDependencies": { "@types/react": "^18 || ^19", From 23c865ee5e77a1d2461f8b9582360de0562195f5 Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 09:42:30 +0530 Subject: [PATCH 14/26] Add the PR number to the changelog entries --- packages/boot/CHANGELOG.md | 2 +- packages/dataviews/CHANGELOG.md | 16 ++++++++-------- packages/media-fields/CHANGELOG.md | 2 +- packages/media-utils/CHANGELOG.md | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/boot/CHANGELOG.md b/packages/boot/CHANGELOG.md index 65fa80dcb3523f..eeefd5e263837c 100644 --- a/packages/boot/CHANGELOG.md +++ b/packages/boot/CHANGELOG.md @@ -8,7 +8,7 @@ ### Bug Fixes -- Only announce the route title when the path changes, so it no longer cuts off notices, such as the one confirming that an item was moved to the trash ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). +- Only announce the route title when the path changes, so it no longer cuts off notices, such as the one confirming that an item was moved to the trash ([#86150](https://github.com/WordPress/gutenberg/pull/86150)). - Generated CSS module class names now change whenever their CSS changes, so they differ from earlier versions. Two versions of the package loaded on the same page, such as one in WordPress Core and an older copy bundled in a plugin, no longer apply their styles to each other's elements ([#85900](https://github.com/WordPress/gutenberg/pull/85900)). ## 0.25.0 (2026-10-20) diff --git a/packages/dataviews/CHANGELOG.md b/packages/dataviews/CHANGELOG.md index 14b3e741c417fe..f76fc84dcc7327 100644 --- a/packages/dataviews/CHANGELOG.md +++ b/packages/dataviews/CHANGELOG.md @@ -9,8 +9,8 @@ ### Enhancements -- Add `opensDialog` for actions whose `callback` opens a dialog. The triggers of these actions and of `RenderModal` actions now have `aria-haspopup="dialog"` ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). -- Replace the close icon that cancels the selection with a "Clear selection" button next to the bulk actions ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). +- Add `opensDialog` for actions whose `callback` opens a dialog. The triggers of these actions and of `RenderModal` actions now have `aria-haspopup="dialog"` ([#86150](https://github.com/WordPress/gutenberg/pull/86150)). +- Replace the close icon that cancels the selection with a "Clear selection" button next to the bulk actions ([#86150](https://github.com/WordPress/gutenberg/pull/86150)). - DataForm: Tighten the line height of field values in the panel layout, so values that wrap onto several lines take less room ([#85828](https://github.com/WordPress/gutenberg/pull/85828)). - Omit trailing ellipses from action button labels ([#85396](https://github.com/WordPress/gutenberg/pull/85396)). - Render table bulk actions outside the table while preserving their placement over the column headers ([#85250](https://github.com/WordPress/gutenberg/pull/85250)). @@ -21,12 +21,12 @@ ### Bug Fixes -- Name the action in the labels of selection checkboxes: "Select [title]" ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). -- Announce when selecting items makes bulk actions available and when clearing the selection removes them ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). -- Move focus to the "Select all" checkbox, or the first control of the layout, when the focused control is removed, such as after moving an item to the trash ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). -- Keep the table media out of the tab order and the accessibility tree when the title next to it leads to the same place, and show a focus ring on it otherwise ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). -- Name list items by their title only, not by all of their content ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). -- Set the grid selection checkbox apart from previews of any color ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). +- Name the action in the labels of selection checkboxes: "Select [title]" ([#86150](https://github.com/WordPress/gutenberg/pull/86150)). +- Announce when selecting items makes bulk actions available and when clearing the selection removes them ([#86150](https://github.com/WordPress/gutenberg/pull/86150)). +- Move focus to the "Select all" checkbox, or the first control of the layout, when the focused control is removed, such as after moving an item to the trash ([#86150](https://github.com/WordPress/gutenberg/pull/86150)). +- Keep the table media out of the tab order and the accessibility tree when the title next to it leads to the same place, and show a focus ring on it otherwise ([#86150](https://github.com/WordPress/gutenberg/pull/86150)). +- Name list items by their title only, not by all of their content ([#86150](https://github.com/WordPress/gutenberg/pull/86150)). +- Set the grid selection checkbox apart from previews of any color ([#86150](https://github.com/WordPress/gutenberg/pull/86150)). - DataForm: Keep the first line of a panel field label that wraps level with its value ([#85828](https://github.com/WordPress/gutenberg/pull/85828)). - Replace the pagination page select with a page number input above 100 pages, so a dataset with tens of thousands of pages no longer freezes the browser ([#85303](https://github.com/WordPress/gutenberg/pull/85303)). diff --git a/packages/media-fields/CHANGELOG.md b/packages/media-fields/CHANGELOG.md index 1b7ab3a9a9c457..f9ad81f91a0be5 100644 --- a/packages/media-fields/CHANGELOG.md +++ b/packages/media-fields/CHANGELOG.md @@ -4,7 +4,7 @@ ### Bug Fixes -- Hide the decorative author avatar from assistive technologies, as the name of the author is next to it ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). +- Hide the decorative author avatar from assistive technologies, as the name of the author is next to it ([#86150](https://github.com/WordPress/gutenberg/pull/86150)). ## 0.23.0 (2026-10-20) diff --git a/packages/media-utils/CHANGELOG.md b/packages/media-utils/CHANGELOG.md index 5147e5769092f8..d6834bae5858ec 100644 --- a/packages/media-utils/CHANGELOG.md +++ b/packages/media-utils/CHANGELOG.md @@ -4,7 +4,7 @@ ### Enhancements -- `MediaEdit`: Show that clicking the preview of a media item replaces it ([#PRNUM](https://github.com/WordPress/gutenberg/pull/PRNUM)). +- `MediaEdit`: Show that clicking the preview of a media item replaces it ([#86150](https://github.com/WordPress/gutenberg/pull/86150)). - `MediaEdit`: Use design system's outline focus ring instead of previous box-shadow based implementation & only animate on items reorder. ([#84940](https://github.com/WordPress/gutenberg/pull/84940)). ## 6.0.0 (2026-10-20) From 702c1b48649d723d0d62ab728391426b568f9ce1 Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 10:29:49 +0530 Subject: [PATCH 15/26] DataViews: Only announce bulk actions in the layouts that show them --- packages/dataviews/src/dataviews/index.tsx | 5 +++++ .../src/dataviews/test/dataviews.jsdom.test.tsx | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/packages/dataviews/src/dataviews/index.tsx b/packages/dataviews/src/dataviews/index.tsx index 3ef17d1343a628..aed7ae3e88372b 100644 --- a/packages/dataviews/src/dataviews/index.tsx +++ b/packages/dataviews/src/dataviews/index.tsx @@ -11,6 +11,7 @@ import deprecated from '@wordpress/deprecated'; import { speak } from '@wordpress/a11y'; import { __ } from '@wordpress/i18n'; import { hasAPossibleBulkAction } from '../components/dataviews-bulk-actions'; +import { LAYOUT_GRID, LAYOUT_TABLE } from '../constants'; import DataViewsContext from '../components/dataviews-context'; import { VIEW_LAYOUTS } from '../components/dataviews-layouts'; import { @@ -143,6 +144,10 @@ function DataViews< Item >( { const [ containerWidth, resizeObserverRef ] = useContainerWidth(); const [ openedFilter, setOpenedFilter ] = useState< string | null >( null ); function hasBulkActionsFor( ids: string[] ) { + // Only the table and grid show the bulk actions. + if ( view.type !== LAYOUT_TABLE && view.type !== LAYOUT_GRID ) { + return false; + } return data.some( ( item ) => ids.includes( getItemId( item ) ) && diff --git a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx index 5887e3af9c8c60..359d59e0fb3f71 100644 --- a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx +++ b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx @@ -373,6 +373,23 @@ describe( 'DataViews component', () => { expect( speak ).toHaveBeenCalledTimes( 2 ); } ); + it( 'does not announce bulk actions in layouts that do not show them', async () => { + vi.mocked( speak ).mockClear(); + // The list scrolls the selected item into view, which jsdom lacks. + window.HTMLElement.prototype.scrollIntoView = vi.fn(); + render( + + ); + const user = userEvent.setup(); + await user.click( + await screen.findByRole( 'button', { name: 'Hello World' } ) + ); + expect( speak ).not.toHaveBeenCalled(); + } ); + it( 'does not announce bulk actions when the consumer clears the selection', () => { vi.mocked( speak ).mockClear(); const props = { onChangeSelection: vi.fn(), actions }; From 8384e30ad96ac977844550fb362c0295b4ebceb5 Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 10:33:32 +0530 Subject: [PATCH 16/26] DataViews: Don't bring focus back after the user moved it away --- .../test/bulk-selection.browser.test.tsx | 34 +++++++++++++++++++ .../dataviews/src/hooks/use-focus-fallback.ts | 18 ++++++++++ 2 files changed, 52 insertions(+) diff --git a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx index ac70cff39f4b21..e404770460ec6d 100644 --- a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx +++ b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx @@ -504,3 +504,37 @@ it( 'moves focus to the select all checkbox when an action removes the item that ) .toHaveFocus(); } ); + +function TableOf( { items }: { items: Post[] } ) { + return ( + {} } + actions={ actions } + paginationInfo={ { totalItems: items.length, totalPages: 1 } } + defaultLayouts={ { table: true } } + /> + ); +} + +it( 'leaves focus alone when it was moved away before the item was removed', async () => { + const { rerender } = await render( ); + const checkbox = page + .getByRole( 'checkbox', { name: 'Select First post', exact: true } ) + .element() as HTMLElement; + checkbox.focus(); + checkbox.blur(); + await rerender( ); + await expect + .element( page.getByRole( 'row', { name: /First post/ } ) ) + .not.toBeInTheDocument(); + expect( checkbox.ownerDocument.body ).toHaveFocus(); +} ); diff --git a/packages/dataviews/src/hooks/use-focus-fallback.ts b/packages/dataviews/src/hooks/use-focus-fallback.ts index b98b1eb5f2f8d9..91d7e3aed8c277 100644 --- a/packages/dataviews/src/hooks/use-focus-fallback.ts +++ b/packages/dataviews/src/hooks/use-focus-fallback.ts @@ -45,6 +45,22 @@ export default function useFocusFallback() { const onFocusIn = ( event: FocusEvent ) => { lastFocused = event.target as HTMLElement; }; + // Focus that leaves for nowhere while the control is still usable was + // moved away on purpose, e.g. by clicking outside any control. Don't + // bring it back when that control goes away later. A modal hiding the + // rest of the page also blurs the control, but focus comes back on + // close. + const onFocusOut = ( event: FocusEvent ) => { + const target = event.target as HTMLElement; + if ( + ! event.relatedTarget && + target.isConnected && + isVisible( target ) && + ! target.closest( '[inert], [aria-hidden="true"]' ) + ) { + lastFocused = null; + } + }; const observer = new MutationObserver( () => { if ( ! lastFocused ) { return; @@ -63,6 +79,7 @@ export default function useFocusFallback() { getFallback( container )?.focus(); } ); container.addEventListener( 'focusin', onFocusIn ); + container.addEventListener( 'focusout', onFocusOut ); observer.observe( container, { childList: true, subtree: true, @@ -71,6 +88,7 @@ export default function useFocusFallback() { } ); return () => { container.removeEventListener( 'focusin', onFocusIn ); + container.removeEventListener( 'focusout', onFocusOut ); observer.disconnect(); }; }, [] ); From c47d7e76ab736669313f2fc5590ce941064d6ef1 Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 10:33:41 +0530 Subject: [PATCH 17/26] DataViews: Use an outline for the focus ring of the table media --- .../src/components/dataviews-layouts/table/style.scss | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-layouts/table/style.scss b/packages/dataviews/src/components/dataviews-layouts/table/style.scss index 5f671c9da67f1d..a44233b2a01bed 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/table/style.scss @@ -302,13 +302,11 @@ border-radius: var(--wpds-border-radius-md); } - // Drawn inside the box, like its border, as the grid does. + // An outline, so it shows in forced colors mode too, drawn inside the + // box as the grid cards do. &:focus-visible { - outline: none; - - &::after { - box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wpds-color-stroke-focus); - } + @include outset-ring__focus(); + outline-offset: calc(-1 * var(--wpds-border-width-focus)); } } From 9a10e19e7bd5cc10d3c5d6502f14ff5e0e4832aa Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 10:54:50 +0530 Subject: [PATCH 18/26] DataViews: Recover focus after an emptied page, a removed focused item, or a dialog that closes later --- .../test/bulk-selection.browser.test.tsx | 117 ++++++++++++++++-- .../dataviews/src/hooks/use-focus-fallback.ts | 33 +++-- 2 files changed, 132 insertions(+), 18 deletions(-) diff --git a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx index e404770460ec6d..bf246b7a831fd3 100644 --- a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx +++ b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx @@ -458,17 +458,30 @@ function TrashableTable() { isPrimary: true, supportsBulk: true, RenderModal: ( { items: itemsToTrash, closeModal } ) => ( - + <> + + + + ), }; return ( @@ -538,3 +551,85 @@ it( 'leaves focus alone when it was moved away before the item was removed', asy .not.toBeInTheDocument(); expect( checkbox.ownerDocument.body ).toHaveFocus(); } ); + +it( 'moves focus to the select all checkbox when a bulk action removes the selected items', async () => { + const user = userEvent.setup(); + await render( ); + await user.click( + page.getByRole( 'checkbox', { name: 'Select First post', exact: true } ) + ); + // The toolbar comes before the rows, which have a Trash button too. + await user.click( + page.getByRole( 'button', { name: 'Trash', exact: true } ).first() + ); + await user.click( + page.getByRole( 'button', { name: 'Confirm', exact: true } ) + ); + await expect + .element( page.getByRole( 'row', { name: /First post/ } ) ) + .not.toBeInTheDocument(); + await expect + .element( + page.getByRole( 'checkbox', { name: 'Select all', exact: true } ) + ) + .toHaveFocus(); +} ); + +it( 'moves focus once there is a control again after the focused item was removed', async () => { + const { rerender } = await render( ); + page.getByRole( 'checkbox', { + name: 'Select First post', + exact: true, + } ) + .element() + .focus(); + await rerender( ); + await rerender( ); + await expect + .element( + page.getByRole( 'checkbox', { name: 'Select all', exact: true } ) + ) + .toHaveFocus(); +} ); + +it( 'moves focus to the select all checkbox when the focused item is removed', async () => { + const { rerender } = await render( ); + page.getByRole( 'checkbox', { + name: 'Select First post', + exact: true, + } ) + .element() + .focus(); + await rerender( ); + await expect + .element( + page.getByRole( 'checkbox', { name: 'Select all', exact: true } ) + ) + .toHaveFocus(); +} ); + +it( 'moves focus to the select all checkbox when a dialog closes after its action removed the items', async () => { + const user = userEvent.setup(); + await render( ); + await user.click( + page.getByRole( 'checkbox', { name: 'Select First post', exact: true } ) + ); + // The toolbar comes before the rows, which have a Trash button too. + await user.click( + page.getByRole( 'button', { name: 'Trash', exact: true } ).first() + ); + await user.click( + page.getByRole( 'button', { name: 'Remove', exact: true } ) + ); + await expect + .element( page.getByRole( 'row', { name: /First post/ } ) ) + .not.toBeInTheDocument(); + await user.click( + page.getByRole( 'button', { name: 'Done', exact: true } ) + ); + await expect + .element( + page.getByRole( 'checkbox', { name: 'Select all', exact: true } ) + ) + .toHaveFocus(); +} ); diff --git a/packages/dataviews/src/hooks/use-focus-fallback.ts b/packages/dataviews/src/hooks/use-focus-fallback.ts index 91d7e3aed8c277..e186ab5afa62d2 100644 --- a/packages/dataviews/src/hooks/use-focus-fallback.ts +++ b/packages/dataviews/src/hooks/use-focus-fallback.ts @@ -49,17 +49,25 @@ export default function useFocusFallback() { // moved away on purpose, e.g. by clicking outside any control. Don't // bring it back when that control goes away later. A modal hiding the // rest of the page also blurs the control, but focus comes back on - // close. + // close. Removing or hiding the control blurs it too, so only decide + // once that is done. const onFocusOut = ( event: FocusEvent ) => { const target = event.target as HTMLElement; if ( - ! event.relatedTarget && - target.isConnected && - isVisible( target ) && - ! target.closest( '[inert], [aria-hidden="true"]' ) + event.relatedTarget || + target.closest( '[inert], [aria-hidden="true"]' ) ) { - lastFocused = null; + return; } + queueMicrotask( () => { + if ( + lastFocused === target && + target.isConnected && + isVisible( target ) + ) { + lastFocused = null; + } + } ); }; const observer = new MutationObserver( () => { if ( ! lastFocused ) { @@ -75,8 +83,15 @@ export default function useFocusFallback() { if ( ! wasRemoved || ! isLost ) { return; } + const fallback = getFallback( container ); + // Nothing to move focus to yet, e.g. while the previous page loads + // after the last item of a page was removed: try again on the next + // change. + if ( ! fallback ) { + return; + } lastFocused = null; - getFallback( container )?.focus(); + fallback.focus(); } ); container.addEventListener( 'focusin', onFocusIn ); container.addEventListener( 'focusout', onFocusOut ); @@ -86,6 +101,10 @@ export default function useFocusFallback() { attributes: true, attributeFilter: [ 'hidden', 'inert' ], } ); + // Modals render outside the layout. One can close after its action + // removed the control it returns focus to, without changing the layout + // any more, so check again when it goes away. + observer.observe( ownerDocument.body, { childList: true } ); return () => { container.removeEventListener( 'focusin', onFocusIn ); container.removeEventListener( 'focusout', onFocusOut ); From d9abd3e6798b00af5c4afc0620cb92a799176028 Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 10:54:55 +0530 Subject: [PATCH 19/26] DataViews: Name list items by their content when the title is hidden --- .../components/dataviews-layouts/list/index.tsx | 5 +++-- .../src/dataviews/test/dataviews.jsdom.test.tsx | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx index 47e01347a86bc3..50133bf4d3e93e 100644 --- a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx @@ -288,8 +288,9 @@ function ListItem< Item >( { role={ infiniteScrollEnabled ? 'article' : 'row' } // Otherwise the row is named after all of its content: the title, // the actions and every field. The fields stay available as the - // description of the item. - aria-labelledby={ labelId } + // description of the item. Without a title, the content is all + // there is to name it by. + aria-labelledby={ renderedTitleField ? labelId : undefined } className={ clsx( { 'is-selected': isSelected, 'is-hovered': isHovered, diff --git a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx index 359d59e0fb3f71..a75a8cfb58dcb2 100644 --- a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx +++ b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx @@ -1744,6 +1744,22 @@ describe( 'DataViews component', () => { ).toHaveAccessibleDescription( /Author\s*Jane/ ); } ); + it( 'names an item by its content when the title is not shown', async () => { + render( + + ); + expect( + await screen.findByRole( 'row', { name: /Jane/ } ) + ).toBeInTheDocument(); + } ); + it( 'should render actions dropdown if actions are supported and passed in for each list item', async () => { render( Date: Mon, 2 Nov 2026 10:55:00 +0530 Subject: [PATCH 20/26] DataViews: Check the loaded items for bulk actions with infinite scroll --- packages/dataviews/src/dataviews/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/dataviews/src/dataviews/index.tsx b/packages/dataviews/src/dataviews/index.tsx index aed7ae3e88372b..3c82ff17c86888 100644 --- a/packages/dataviews/src/dataviews/index.tsx +++ b/packages/dataviews/src/dataviews/index.tsx @@ -148,7 +148,9 @@ function DataViews< Item >( { if ( view.type !== LAYOUT_TABLE && view.type !== LAYOUT_GRID ) { return false; } - return data.some( + // The items the toolbar works on, which with infinite scroll keep the + // selected items of the pages loaded before. + return displayData.some( ( item ) => ids.includes( getItemId( item ) ) && hasAPossibleBulkAction( actions, item ) From b51674c028ec41d1428c120536a41b641a58aaaf Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 11:54:55 +0530 Subject: [PATCH 21/26] DataViews: Let popovers, modals and loading settle before recovering focus --- .../test/bulk-selection.browser.test.tsx | 30 +++++++++- .../dataviews/test/dataviews.jsdom.test.tsx | 17 ------ .../dataviews/src/hooks/use-focus-fallback.ts | 56 ++++++++++++++++--- 3 files changed, 77 insertions(+), 26 deletions(-) diff --git a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx index bf246b7a831fd3..6524a1aec30c9e 100644 --- a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx +++ b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx @@ -1,6 +1,7 @@ import { render } from 'vitest-browser-react'; import { page, userEvent } from 'vitest/browser'; -import { afterEach, beforeEach, expect, it } from 'vitest'; +import { afterEach, beforeEach, expect, it, vi } from 'vitest'; +import { speak } from '@wordpress/a11y'; import { useLayoutEffect, useState } from '@wordpress/element'; import '@wordpress/theme/design-tokens.css'; import DataViews from '../index'; @@ -8,6 +9,8 @@ import type { Action, Field, View } from '../../types'; import filterSortAndPaginate from '../../utils/filter-sort-and-paginate'; import '../../style.scss'; +vi.mock( import( '@wordpress/a11y' ), () => ( { speak: vi.fn() } ) as any ); + const initialViewport = { width: window.innerWidth, height: window.innerHeight, @@ -633,3 +636,28 @@ it( 'moves focus to the select all checkbox when a dialog closes after its actio ) .toHaveFocus(); } ); + +it( 'does not announce bulk actions in layouts that do not show them', async () => { + vi.mocked( speak ).mockClear(); + const user = userEvent.setup(); + await render( + {} } + actions={ actions } + paginationInfo={ { totalItems: posts.length, totalPages: 1 } } + defaultLayouts={ { list: true } } + /> + ); + await user.click( + page.getByRole( 'button', { name: 'First post', exact: true } ) + ); + await expect + .element( + page.getByRole( 'button', { name: 'First post', exact: true } ) + ) + .toHaveAttribute( 'aria-pressed', 'true' ); + expect( speak ).not.toHaveBeenCalled(); +} ); diff --git a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx index a75a8cfb58dcb2..ec53684be91d14 100644 --- a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx +++ b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx @@ -373,23 +373,6 @@ describe( 'DataViews component', () => { expect( speak ).toHaveBeenCalledTimes( 2 ); } ); - it( 'does not announce bulk actions in layouts that do not show them', async () => { - vi.mocked( speak ).mockClear(); - // The list scrolls the selected item into view, which jsdom lacks. - window.HTMLElement.prototype.scrollIntoView = vi.fn(); - render( - - ); - const user = userEvent.setup(); - await user.click( - await screen.findByRole( 'button', { name: 'Hello World' } ) - ); - expect( speak ).not.toHaveBeenCalled(); - } ); - it( 'does not announce bulk actions when the consumer clears the selection', () => { vi.mocked( speak ).mockClear(); const props = { onChangeSelection: vi.fn(), actions }; diff --git a/packages/dataviews/src/hooks/use-focus-fallback.ts b/packages/dataviews/src/hooks/use-focus-fallback.ts index e186ab5afa62d2..cc19f0a16a5110 100644 --- a/packages/dataviews/src/hooks/use-focus-fallback.ts +++ b/packages/dataviews/src/hooks/use-focus-fallback.ts @@ -21,7 +21,13 @@ function isVisible( element: Element ) { function getFallback( container: HTMLElement ) { const controls = Array.from( container.querySelectorAll< HTMLElement >( FOCUSABLE_SELECTOR ) - ).filter( ( element ) => element.tabIndex >= 0 && isVisible( element ) ); + ).filter( + ( element ) => + element.tabIndex >= 0 && + isVisible( element ) && + // The layout is inert while it loads, e.g. after an action. + ! element.closest( '[inert]' ) + ); return ( controls.find( ( element ) => @@ -69,8 +75,13 @@ export default function useFocusFallback() { } } ); }; - const observer = new MutationObserver( () => { - if ( ! lastFocused ) { + const restoreFocus = () => { + // Behind an open modal, focus belongs to the modal. Check again + // once it closes. + if ( + ! lastFocused || + container.closest( '[inert], [aria-hidden="true"]' ) + ) { return; } const { activeElement } = ownerDocument; @@ -90,9 +101,27 @@ export default function useFocusFallback() { if ( ! fallback ) { return; } - lastFocused = null; + // Once it lands, `onFocusIn` tracks the fallback instead. Until + // then, the next change tries again. fallback.focus(); - } ); + }; + // Wait a frame, so that a closing popover or modal returns focus to its + // trigger first. Focus is only lost if it is still nowhere after that. + let frame: number | undefined; + const scheduleRestore = () => { + if ( ! lastFocused ) { + return; + } + const { defaultView } = ownerDocument; + if ( frame !== undefined ) { + defaultView?.cancelAnimationFrame( frame ); + } + frame = defaultView?.requestAnimationFrame( () => { + frame = undefined; + restoreFocus(); + } ); + }; + const observer = new MutationObserver( scheduleRestore ); container.addEventListener( 'focusin', onFocusIn ); container.addEventListener( 'focusout', onFocusOut ); observer.observe( container, { @@ -101,14 +130,25 @@ export default function useFocusFallback() { attributes: true, attributeFilter: [ 'hidden', 'inert' ], } ); - // Modals render outside the layout. One can close after its action - // removed the control it returns focus to, without changing the layout - // any more, so check again when it goes away. + // Modals render outside the layout, and hide the rest of the page while + // open. One can close after its action removed the control it returns + // focus to, without changing the layout any more, so check again when + // it goes away and when the page is shown again. observer.observe( ownerDocument.body, { childList: true } ); + const pageObserver = new MutationObserver( scheduleRestore ); + pageObserver.observe( ownerDocument.body, { + subtree: true, + attributes: true, + attributeFilter: [ 'aria-hidden', 'inert' ], + } ); return () => { container.removeEventListener( 'focusin', onFocusIn ); container.removeEventListener( 'focusout', onFocusOut ); observer.disconnect(); + pageObserver.disconnect(); + if ( frame !== undefined ) { + ownerDocument.defaultView?.cancelAnimationFrame( frame ); + } }; }, [] ); } From f95a1f17969a63e63c502403a88aeb2883758024 Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 11:55:01 +0530 Subject: [PATCH 22/26] Tests: Find list items by their button and cover focus after a bulk trash --- .../dataviews-list-layout-keyboard.spec.js | 33 ++++++++++++----- test/e2e/specs/site-editor/page-list.spec.js | 37 +++++++++++++++++++ test/performance/specs/site-editor.spec.js | 6 ++- 3 files changed, 65 insertions(+), 11 deletions(-) diff --git a/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js b/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js index cf2284a9e02266..5391a68d830511 100644 --- a/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js +++ b/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js @@ -143,10 +143,14 @@ test.describe( 'Dataviews List Layout', () => { // Use arrow up/down to move through the list. await page.keyboard.press( 'ArrowDown' ); - await expect( page.getByLabel( 'Page Two' ) ).toBeFocused(); + await expect( + page.getByRole( 'button', { name: 'Page Two', exact: true } ) + ).toBeFocused(); await page.keyboard.press( 'ArrowUp' ); - await expect( page.getByLabel( 'Page One' ) ).toBeFocused(); + await expect( + page.getByRole( 'button', { name: 'Page One', exact: true } ) + ).toBeFocused(); } ); test( 'Actions are reachable via RIGHT/LEFT arrow keys', async ( { @@ -166,7 +170,8 @@ test.describe( 'Dataviews List Layout', () => { await expect( page .getByRole( 'row', { - name: `Page One ${ primaryActionLabel } Actions`, + name: 'Page One', + exact: true, } ) .getByRole( 'button', { name: primaryActionLabel } ) ).toBeFocused(); @@ -175,7 +180,8 @@ test.describe( 'Dataviews List Layout', () => { await expect( page .getByRole( 'row', { - name: `Page One ${ primaryActionLabel } Actions`, + name: 'Page One', + exact: true, } ) .getByLabel( 'Actions' ) ).toBeFocused(); @@ -184,13 +190,16 @@ test.describe( 'Dataviews List Layout', () => { await expect( page .getByRole( 'row', { - name: `Page One ${ primaryActionLabel } Actions`, + name: 'Page One', + exact: true, } ) .getByRole( 'button', { name: primaryActionLabel } ) ).toBeFocused(); await page.keyboard.press( 'ArrowLeft' ); - await expect( page.getByLabel( 'Page One' ) ).toBeFocused(); + await expect( + page.getByRole( 'button', { name: 'Page One', exact: true } ) + ).toBeFocused(); } ); test( 'Search input retains focus while typing', async ( { page } ) => { @@ -237,7 +246,8 @@ test.describe( 'Dataviews List Layout', () => { await expect( page .getByRole( 'row', { - name: `Page Two ${ primaryActionLabel } Actions`, + name: 'Page Two', + exact: true, } ) .getByRole( 'button', { name: primaryActionLabel } ) ).toBeFocused(); @@ -246,7 +256,8 @@ test.describe( 'Dataviews List Layout', () => { await expect( page .getByRole( 'row', { - name: `Page One ${ primaryActionLabel } Actions`, + name: 'Page One', + exact: true, } ) .getByRole( 'button', { name: primaryActionLabel } ) ).toBeFocused(); @@ -257,7 +268,8 @@ test.describe( 'Dataviews List Layout', () => { await expect( page .getByRole( 'row', { - name: `Page Two ${ primaryActionLabel } Actions`, + name: 'Page Two', + exact: true, } ) .getByLabel( 'Actions' ) ).toBeFocused(); @@ -266,7 +278,8 @@ test.describe( 'Dataviews List Layout', () => { await expect( page .getByRole( 'row', { - name: `Page One ${ primaryActionLabel } Actions`, + name: 'Page One', + exact: true, } ) .getByLabel( 'Actions' ) ).toBeFocused(); diff --git a/test/e2e/specs/site-editor/page-list.spec.js b/test/e2e/specs/site-editor/page-list.spec.js index a363b7dd54949c..218466b9cdc40d 100644 --- a/test/e2e/specs/site-editor/page-list.spec.js +++ b/test/e2e/specs/site-editor/page-list.spec.js @@ -661,6 +661,43 @@ test.describe( 'Page List', () => { } ); } ); + test.describe( 'Trash', () => { + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.deleteAllPages(); + await createPages( requestUtils ); + } ); + + test( 'moves focus to the select all checkbox after trashing the selected page', async ( { + page, + } ) => { + await page.getByRole( 'button', { name: 'Layout' } ).click(); + await page.getByRole( 'menuitemradio', { name: 'Table' } ).click(); + const table = page.getByRole( 'table' ); + await table + .getByRole( 'checkbox', { name: 'Select Sample Page' } ) + .click(); + // The toolbar comes before the rows, which have a Trash button too. + await page + .locator( '.dataviews-bulk-actions' ) + .getByRole( 'button', { name: 'Trash', exact: true } ) + .click(); + await page + .getByRole( 'dialog' ) + .getByRole( 'button', { name: 'Trash', exact: true } ) + .click(); + + await expect( + table.getByRole( 'row', { name: /Sample Page/ } ) + ).toBeHidden(); + await expect( + table.getByRole( 'checkbox', { + name: 'Select all', + exact: true, + } ) + ).toBeFocused(); + } ); + } ); + test.describe( 'Quick Edit Date Timezone Consistency', () => { const PAGE_DATE_GMT = '2026-02-15T17:30:00'; // UTC-5 offset means the displayed time should be 5 hours earlier. diff --git a/test/performance/specs/site-editor.spec.js b/test/performance/specs/site-editor.spec.js index f00f19940f83e3..237c9f5df82861 100644 --- a/test/performance/specs/site-editor.spec.js +++ b/test/performance/specs/site-editor.spec.js @@ -459,7 +459,11 @@ test.describe( 'Site Editor Performance', () => { await Promise.all( Array.from( { length: perPage }, async ( el, index ) => { return await page - .getByLabel( `Page (${ index })` ) + .getByRole( 'button', { + name: `Page (${ index })`, + exact: true, + } ) + .first() .waitFor( { state: 'attached' } ); } ) ); From 70e981fd0f6323f8ce160ad21107b632a2a96ec1 Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 13:05:30 +0530 Subject: [PATCH 23/26] DataViews: Forget the focused item once focus moves on, and fall back to the search when no items are left --- .../src/components/dataviews-layout/index.tsx | 6 +- .../test/bulk-selection.browser.test.tsx | 57 ++++++++++++++++++- .../dataviews/src/hooks/use-focus-fallback.ts | 42 ++++++++++++-- 3 files changed, 95 insertions(+), 10 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-layout/index.tsx b/packages/dataviews/src/components/dataviews-layout/index.tsx index 22962f934a002b..240f1a31e94319 100644 --- a/packages/dataviews/src/components/dataviews-layout/index.tsx +++ b/packages/dataviews/src/components/dataviews-layout/index.tsx @@ -22,6 +22,7 @@ export default function DataViewsLayout( { className }: DataViewsLayoutProps ) { getItemLevel, hasInitiallyLoaded, isLoading, + paginationInfo, view, onChangeView, selection, @@ -35,7 +36,10 @@ export default function DataViewsLayout( { className }: DataViewsLayoutProps ) { empty =

{ __( 'No results' ) }

, } = useContext( DataViewsContext ); - const layoutRef = useMergeRefs( [ containerRef, useFocusFallback() ] ); + const layoutRef = useMergeRefs( [ + containerRef, + useFocusFallback( ! isLoading && paginationInfo.totalItems === 0 ), + ] ); const isDelayedInitialLoading = useDelayedLoading( ! hasInitiallyLoaded, { delay: 200, } ); diff --git a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx index 6524a1aec30c9e..867b4ea4c37f92 100644 --- a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx +++ b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx @@ -521,7 +521,21 @@ it( 'moves focus to the select all checkbox when an action removes the item that .toHaveFocus(); } ); -function TableOf( { items }: { items: Post[] } ) { +// Focus is restored a frame after the change, so wait for it before +// checking that it was left alone. +function nextFrames() { + return new Promise( ( resolve ) => + requestAnimationFrame( () => requestAnimationFrame( resolve ) ) + ); +} + +function TableOf( { + items, + totalItems = items.length, +}: { + items: Post[]; + totalItems?: number; +} ) { return ( {} } actions={ actions } - paginationInfo={ { totalItems: items.length, totalPages: 1 } } + paginationInfo={ { totalItems, totalPages: 1 } } defaultLayouts={ { table: true } } /> ); @@ -552,6 +566,7 @@ it( 'leaves focus alone when it was moved away before the item was removed', asy await expect .element( page.getByRole( 'row', { name: /First post/ } ) ) .not.toBeInTheDocument(); + await nextFrames(); expect( checkbox.ownerDocument.body ).toHaveFocus(); } ); @@ -586,7 +601,8 @@ it( 'moves focus once there is a control again after the focused item was remove } ) .element() .focus(); - await rerender( ); + // Like the last item of a page, while the page before it loads. + await rerender( ); await rerender( ); await expect .element( @@ -661,3 +677,38 @@ it( 'does not announce bulk actions in layouts that do not show them', async () .toHaveAttribute( 'aria-pressed', 'true' ); expect( speak ).not.toHaveBeenCalled(); } ); + +it( 'moves focus to the search when no items are left', async () => { + const { rerender } = await render( ); + page.getByRole( 'checkbox', { + name: 'Select First post', + exact: true, + } ) + .element() + .focus(); + await rerender( ); + await expect + .element( page.getByRole( 'searchbox', { name: 'Search' } ) ) + .toHaveFocus(); +} ); + +it( 'forgets the focused item once focus moves to another control', async () => { + const { rerender } = await render( ); + page.getByRole( 'checkbox', { + name: 'Select First post', + exact: true, + } ) + .element() + .focus(); + const search = page + .getByRole( 'searchbox', { name: 'Search' } ) + .element() as HTMLElement; + search.focus(); + search.blur(); + await rerender( ); + await expect + .element( page.getByRole( 'row', { name: /First post/ } ) ) + .not.toBeInTheDocument(); + await nextFrames(); + expect( search.ownerDocument.body ).toHaveFocus(); +} ); diff --git a/packages/dataviews/src/hooks/use-focus-fallback.ts b/packages/dataviews/src/hooks/use-focus-fallback.ts index cc19f0a16a5110..13339b4e9f3db8 100644 --- a/packages/dataviews/src/hooks/use-focus-fallback.ts +++ b/packages/dataviews/src/hooks/use-focus-fallback.ts @@ -1,4 +1,5 @@ import { useRefEffect } from '@wordpress/compose'; +import { useLayoutEffect, useRef } from '@wordpress/element'; const FOCUSABLE_SELECTOR = [ 'button:not([disabled])', @@ -43,8 +44,15 @@ function getFallback( container: HTMLElement ) { * focus to is gone by the time the modal closes. Without this, focus falls * back to the document body and keyboard users have to start over from the * top of the page. + * + * @param isEmpty Whether there are no items left to show, in which case the + * layout has no controls and focus moves to the ones around it. */ -export default function useFocusFallback() { +export default function useFocusFallback( isEmpty: boolean ) { + const isEmptyRef = useRef( isEmpty ); + useLayoutEffect( () => { + isEmptyRef.current = isEmpty; + }, [ isEmpty ] ); return useRefEffect( ( container: HTMLElement ) => { const { ownerDocument } = container; let lastFocused: HTMLElement | null = null; @@ -59,10 +67,22 @@ export default function useFocusFallback() { // once that is done. const onFocusOut = ( event: FocusEvent ) => { const target = event.target as HTMLElement; - if ( - event.relatedTarget || - target.closest( '[inert], [aria-hidden="true"]' ) - ) { + const next = event.relatedTarget as HTMLElement | null; + // Focus moved to another control outside the layout, e.g. the + // search, was moved on purpose too. Menus and dialogs opened from + // the layout hand it back, so keep tracking for them. + if ( next ) { + if ( + ! container.contains( next ) && + ! next.closest( + '[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]' + ) + ) { + lastFocused = null; + } + return; + } + if ( target.closest( '[inert], [aria-hidden="true"]' ) ) { return; } queueMicrotask( () => { @@ -94,7 +114,17 @@ export default function useFocusFallback() { if ( ! wasRemoved || ! isLost ) { return; } - const fallback = getFallback( container ); + // With no items left, the layout has no controls: use the ones + // around it, such as the search. + const fallback = + getFallback( container ) ?? + ( isEmptyRef.current + ? getFallback( + container.closest< HTMLElement >( + '.dataviews-wrapper' + ) ?? container + ) + : undefined ); // Nothing to move focus to yet, e.g. while the previous page loads // after the last item of a page was removed: try again on the next // change. From 6cbc680d18127d99ee1169c78c6227d706ae4fa6 Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 13:57:42 +0530 Subject: [PATCH 24/26] DataViews: Track focus across the page in the focus fallback Forget the focused control once focus moves on to another one, including a fallback outside the layout. Keep it while a menu, dialog or popover opened from the layout has focus, but not the dialog the whole view is in. Bring focus back to a control that is still there once loading ends, leave the items infinite scroll unloads alone, and fall back to the controls around a picker too. --- .../src/components/dataviews-layout/index.tsx | 5 +- .../test/bulk-selection.browser.test.tsx | 188 +++++++++++++++--- .../dataviews/src/hooks/use-focus-fallback.ts | 100 ++++++---- 3 files changed, 235 insertions(+), 58 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-layout/index.tsx b/packages/dataviews/src/components/dataviews-layout/index.tsx index 240f1a31e94319..f05e91f27f67dc 100644 --- a/packages/dataviews/src/components/dataviews-layout/index.tsx +++ b/packages/dataviews/src/components/dataviews-layout/index.tsx @@ -38,7 +38,10 @@ export default function DataViewsLayout( { className }: DataViewsLayoutProps ) { const layoutRef = useMergeRefs( [ containerRef, - useFocusFallback( ! isLoading && paginationInfo.totalItems === 0 ), + useFocusFallback( { + isEmpty: ! isLoading && paginationInfo.totalItems === 0, + isInfiniteScroll: !! view.infiniteScrollEnabled, + } ), ] ); const isDelayedInitialLoading = useDelayedLoading( ! hasInitiallyLoaded, { delay: 200, diff --git a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx index 867b4ea4c37f92..88e4b2052afbe2 100644 --- a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx +++ b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx @@ -5,6 +5,7 @@ import { speak } from '@wordpress/a11y'; import { useLayoutEffect, useState } from '@wordpress/element'; import '@wordpress/theme/design-tokens.css'; import DataViews from '../index'; +import useFocusFallback from '../../hooks/use-focus-fallback'; import type { Action, Field, View } from '../../types'; import filterSortAndPaginate from '../../utils/filter-sort-and-paginate'; import '../../style.scss'; @@ -532,9 +533,11 @@ function nextFrames() { function TableOf( { items, totalItems = items.length, + infiniteScroll, }: { items: Post[]; totalItems?: number; + infiniteScroll?: boolean; } ) { return ( {} } actions={ actions } @@ -570,29 +574,6 @@ it( 'leaves focus alone when it was moved away before the item was removed', asy expect( checkbox.ownerDocument.body ).toHaveFocus(); } ); -it( 'moves focus to the select all checkbox when a bulk action removes the selected items', async () => { - const user = userEvent.setup(); - await render( ); - await user.click( - page.getByRole( 'checkbox', { name: 'Select First post', exact: true } ) - ); - // The toolbar comes before the rows, which have a Trash button too. - await user.click( - page.getByRole( 'button', { name: 'Trash', exact: true } ).first() - ); - await user.click( - page.getByRole( 'button', { name: 'Confirm', exact: true } ) - ); - await expect - .element( page.getByRole( 'row', { name: /First post/ } ) ) - .not.toBeInTheDocument(); - await expect - .element( - page.getByRole( 'checkbox', { name: 'Select all', exact: true } ) - ) - .toHaveFocus(); -} ); - it( 'moves focus once there is a control again after the focused item was removed', async () => { const { rerender } = await render( ); page.getByRole( 'checkbox', { @@ -712,3 +693,164 @@ it( 'forgets the focused item once focus moves to another control', async () => await nextFrames(); expect( search.ownerDocument.body ).toHaveFocus(); } ); + +it( 'leaves focus alone after the search took it and the items come back', async () => { + const { rerender } = await render( ); + page.getByRole( 'checkbox', { + name: 'Select First post', + exact: true, + } ) + .element() + .focus(); + await rerender( ); + const search = page.getByRole( 'searchbox', { name: 'Search' } ); + await expect.element( search ).toHaveFocus(); + const searchElement = search.element() as HTMLElement; + searchElement.blur(); + await rerender( ); + await expect + .element( page.getByRole( 'row', { name: /Second post/ } ) ) + .toBeInTheDocument(); + await nextFrames(); + expect( searchElement.ownerDocument.body ).toHaveFocus(); +} ); + +it( 'leaves focus to a dialog that closes without removing anything', async () => { + const user = userEvent.setup(); + await render( ); + const trigger = page + .getByRole( 'row', { name: /First post/ } ) + .getByRole( 'button', { name: 'Trash', exact: true } ); + await user.click( trigger ); + await user.click( + page.getByRole( 'button', { name: 'Done', exact: true } ) + ); + await nextFrames(); + await expect.element( trigger ).toHaveFocus(); +} ); + +function LoadingTable( { isLoading }: { isLoading: boolean } ) { + const renameAction: Action< Post > = { + id: 'rename', + label: 'Rename', + isPrimary: true, + RenderModal: ( { closeModal } ) => ( + + ), + }; + return ( + {} } + actions={ [ renameAction ] } + isLoading={ isLoading } + paginationInfo={ { totalItems: posts.length, totalPages: 1 } } + defaultLayouts={ { table: true } } + /> + ); +} + +it( 'brings focus back to the trigger of a dialog that closed while loading', async () => { + const user = userEvent.setup(); + const { rerender } = await render( ); + const trigger = page + .getByRole( 'row', { name: /First post/ } ) + .getByRole( 'button', { name: 'Rename', exact: true } ); + await user.click( trigger ); + // The action saves, so the view loads, and the dialog closes meanwhile: + // it can't return focus to its trigger in the inert table. + await rerender( ); + await user.click( + page.getByRole( 'button', { name: 'Done', exact: true } ) + ); + await rerender( ); + await expect.element( trigger ).toHaveFocus(); +} ); + +function FallbackList( { + items, + isInfiniteScroll, +}: { + items: string[]; + isInfiniteScroll: boolean; +} ) { + const ref = useFocusFallback( { isEmpty: false, isInfiniteScroll } ); + return ( +
+ { items.map( ( item ) => ( + + ) ) } +
+ ); +} + +async function removeFocusedItem( isInfiniteScroll: boolean ) { + const { rerender } = await render( + + ); + const one = page + .getByRole( 'button', { name: 'One', exact: true } ) + .element() as HTMLElement; + one.focus(); + await rerender( + + ); + await nextFrames(); + return one.ownerDocument; +} + +it( 'moves focus on when the focused item is removed', async () => { + await removeFocusedItem( false ); + await expect + .element( page.getByRole( 'button', { name: 'Two', exact: true } ) ) + .toHaveFocus(); +} ); + +it( 'leaves focus alone when infinite scroll unloads the focused item', async () => { + const { body } = await removeFocusedItem( true ); + expect( body ).toHaveFocus(); +} ); + +it( 'moves focus within a view inside a dialog', async () => { + const { rerender } = await render( +
+ +
+ ); + page.getByRole( 'checkbox', { + name: 'Select First post', + exact: true, + } ) + .element() + .focus(); + const search = page + .getByRole( 'searchbox', { name: 'Search' } ) + .element() as HTMLElement; + // Moving on to another control of the dialog is moving on. + search.focus(); + search.blur(); + await rerender( +
+ +
+ ); + await expect + .element( page.getByRole( 'row', { name: /First post/ } ) ) + .not.toBeInTheDocument(); + await nextFrames(); + expect( search.ownerDocument.body ).toHaveFocus(); +} ); diff --git a/packages/dataviews/src/hooks/use-focus-fallback.ts b/packages/dataviews/src/hooks/use-focus-fallback.ts index 13339b4e9f3db8..23122c13b58e85 100644 --- a/packages/dataviews/src/hooks/use-focus-fallback.ts +++ b/packages/dataviews/src/hooks/use-focus-fallback.ts @@ -45,19 +45,45 @@ function getFallback( container: HTMLElement ) { * back to the document body and keyboard users have to start over from the * top of the page. * - * @param isEmpty Whether there are no items left to show, in which case the - * layout has no controls and focus moves to the ones around it. + * @param options Options. + * @param options.isEmpty Whether there are no items left to show, in + * which case the layout has no controls and + * focus moves to the ones around it. + * @param options.isInfiniteScroll Whether items load as the view scrolls, + * which also unloads the ones scrolled past. */ -export default function useFocusFallback( isEmpty: boolean ) { - const isEmptyRef = useRef( isEmpty ); +export default function useFocusFallback( { + isEmpty, + isInfiniteScroll, +}: { + isEmpty: boolean; + isInfiniteScroll: boolean; +} ) { + const optionsRef = useRef( { isEmpty, isInfiniteScroll } ); useLayoutEffect( () => { - isEmptyRef.current = isEmpty; - }, [ isEmpty ] ); + optionsRef.current = { isEmpty, isInfiniteScroll }; + }, [ isEmpty, isInfiniteScroll ] ); return useRefEffect( ( container: HTMLElement ) => { const { ownerDocument } = container; + // The control to bring focus back to if it goes away while focused. It + // is the last control focused in the layout, kept while focus is in a + // menu or dialog opened from it, which hand focus back when they close. let lastFocused: HTMLElement | null = null; + const isHandOff = ( element: HTMLElement ) => { + const popup = element.closest( + '[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"], .components-popover' + ); + // Not the dialog the whole view is in, such as a media modal. + return !! popup && ! popup.contains( container ); + }; const onFocusIn = ( event: FocusEvent ) => { - lastFocused = event.target as HTMLElement; + const target = event.target as HTMLElement; + if ( container.contains( target ) ) { + lastFocused = target; + } else if ( ! isHandOff( target ) ) { + // Focus moved on to another control, e.g. the search. + lastFocused = null; + } }; // Focus that leaves for nowhere while the control is still usable was // moved away on purpose, e.g. by clicking outside any control. Don't @@ -67,29 +93,20 @@ export default function useFocusFallback( isEmpty: boolean ) { // once that is done. const onFocusOut = ( event: FocusEvent ) => { const target = event.target as HTMLElement; - const next = event.relatedTarget as HTMLElement | null; - // Focus moved to another control outside the layout, e.g. the - // search, was moved on purpose too. Menus and dialogs opened from - // the layout hand it back, so keep tracking for them. - if ( next ) { - if ( - ! container.contains( next ) && - ! next.closest( - '[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]' - ) - ) { - lastFocused = null; - } - return; - } - if ( target.closest( '[inert], [aria-hidden="true"]' ) ) { + if ( + event.relatedTarget || + ! ( container.contains( target ) || isHandOff( target ) ) || + target.closest( '[inert], [aria-hidden="true"]' ) + ) { return; } queueMicrotask( () => { + const { activeElement } = ownerDocument; if ( - lastFocused === target && target.isConnected && - isVisible( target ) + isVisible( target ) && + // Unless focus went on to another control meanwhile. + ( ! activeElement || activeElement === ownerDocument.body ) ) { lastFocused = null; } @@ -111,17 +128,31 @@ export default function useFocusFallback( isEmpty: boolean ) { ! activeElement || activeElement === ownerDocument.body || ( activeElement === lastFocused && wasRemoved ); - if ( ! wasRemoved || ! isLost ) { + if ( ! isLost ) { + return; + } + // Still there, but focus was knocked off it, e.g. as the layout + // turned inert to load while a modal returned focus to it. + if ( ! wasRemoved ) { + if ( ! lastFocused.closest( '[inert]' ) ) { + lastFocused.focus(); + } + return; + } + // Infinite scroll unloads the items scrolled past, which is not + // the focused item going away. + if ( optionsRef.current.isInfiniteScroll ) { + lastFocused = null; return; } // With no items left, the layout has no controls: use the ones // around it, such as the search. const fallback = getFallback( container ) ?? - ( isEmptyRef.current + ( optionsRef.current.isEmpty ? getFallback( container.closest< HTMLElement >( - '.dataviews-wrapper' + '.dataviews-wrapper, .dataviews-picker-wrapper' ) ?? container ) : undefined ); @@ -131,8 +162,9 @@ export default function useFocusFallback( isEmpty: boolean ) { if ( ! fallback ) { return; } - // Once it lands, `onFocusIn` tracks the fallback instead. Until - // then, the next change tries again. + // Once it lands, `onFocusIn` tracks the fallback, or stops tracking + // for one outside the layout. Until then, the next change tries + // again. fallback.focus(); }; // Wait a frame, so that a closing popover or modal returns focus to its @@ -152,8 +184,8 @@ export default function useFocusFallback( isEmpty: boolean ) { } ); }; const observer = new MutationObserver( scheduleRestore ); - container.addEventListener( 'focusin', onFocusIn ); - container.addEventListener( 'focusout', onFocusOut ); + ownerDocument.addEventListener( 'focusin', onFocusIn ); + ownerDocument.addEventListener( 'focusout', onFocusOut ); observer.observe( container, { childList: true, subtree: true, @@ -172,8 +204,8 @@ export default function useFocusFallback( isEmpty: boolean ) { attributeFilter: [ 'aria-hidden', 'inert' ], } ); return () => { - container.removeEventListener( 'focusin', onFocusIn ); - container.removeEventListener( 'focusout', onFocusOut ); + ownerDocument.removeEventListener( 'focusin', onFocusIn ); + ownerDocument.removeEventListener( 'focusout', onFocusOut ); observer.disconnect(); pageObserver.disconnect(); if ( frame !== undefined ) { From 4ee7badb7b86da95cd81559db80a5fe5ebff9c3d Mon Sep 17 00:00:00 2001 From: Hrithik Dalal Date: Mon, 2 Nov 2026 14:40:06 +0530 Subject: [PATCH 25/26] DataViews: Only skip focus recovery for items infinite scroll unloads off screen Tell unloading apart from an action removing the focused item by whether the item was on screen, measured against the scroll container with a margin and ignoring sideways scrolling. Also forget a control hidden on its own, such as the table media, once focus leaves it, refocus without scrolling, and name list rows by their content when the title is empty. --- .../dataviews-layouts/list/index.tsx | 6 +- .../test/bulk-selection.browser.test.tsx | 128 ++++++++++++++---- .../dataviews/test/dataviews.jsdom.test.tsx | 16 +++ .../dataviews/src/hooks/use-focus-fallback.ts | 85 ++++++++++-- 4 files changed, 194 insertions(+), 41 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx index 50133bf4d3e93e..3b35e27ddf37f7 100644 --- a/packages/dataviews/src/components/dataviews-layouts/list/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/list/index.tsx @@ -290,7 +290,11 @@ function ListItem< Item >( { // the actions and every field. The fields stay available as the // description of the item. Without a title, the content is all // there is to name it by. - aria-labelledby={ renderedTitleField ? labelId : undefined } + aria-labelledby={ + renderedTitleField && titleField?.getValue?.( { item } ) + ? labelId + : undefined + } className={ clsx( { 'is-selected': isSelected, 'is-hovered': isHovered, diff --git a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx index 88e4b2052afbe2..fd8a55848685d1 100644 --- a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx +++ b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx @@ -775,54 +775,122 @@ it( 'brings focus back to the trigger of a dialog that closed while loading', as await expect.element( trigger ).toHaveFocus(); } ); +const LIST = Array.from( { length: 30 }, ( _, index ) => `Item ${ index }` ); + function FallbackList( { - items, - isInfiniteScroll, + items = LIST, + hidden = [], + ariaHidden = [], + isInfiniteScroll = false, }: { - items: string[]; - isInfiniteScroll: boolean; + items?: string[]; + hidden?: string[]; + ariaHidden?: string[]; + isInfiniteScroll?: boolean; } ) { const ref = useFocusFallback( { isEmpty: false, isInfiniteScroll } ); return ( -
- { items.map( ( item ) => ( - - ) ) } +
+
+ { items.map( ( item ) => ( +
+ +
+ ) ) } +
); } -async function removeFocusedItem( isInfiniteScroll: boolean ) { - const { rerender } = await render( - - ); - const one = page - .getByRole( 'button', { name: 'One', exact: true } ) +function focusItem( name: string ) { + const element = page + .getByRole( 'button', { name, exact: true, includeHidden: true } ) .element() as HTMLElement; - one.focus(); + element.focus(); + return element; +} + +it.each( [ false, true ] )( + 'moves focus on when the focused item is removed, with infinite scroll %s', + async ( isInfiniteScroll ) => { + const { rerender } = await render( + + ); + focusItem( 'Item 0' ); + await nextFrames(); + // Like an action removing the item it was triggered on. + await rerender( + + ); + await expect + .element( + page.getByRole( 'button', { name: 'Item 1', exact: true } ) + ) + .toHaveFocus(); + } +); + +it( 'moves focus on when the focused control is hidden, with infinite scroll', async () => { + const { rerender } = await render( ); + focusItem( 'Item 0' ); + await nextFrames(); + await rerender(
@@ -893,6 +900,21 @@ it( 'forgets a control hidden on its own once focus leaves it', async () => { expect( item.ownerDocument.body ).toHaveFocus(); } ); +it( 'skips disabled and hidden controls when moving focus on', async () => { + const { rerender } = await render( ); + focusItem( 'Item 0' ); + await rerender( + + ); + await expect + .element( page.getByRole( 'button', { name: 'Item 3', exact: true } ) ) + .toHaveFocus(); +} ); + it( 'moves focus within a view inside a dialog', async () => { const { rerender } = await render(
diff --git a/packages/dataviews/src/hooks/use-focus-fallback.ts b/packages/dataviews/src/hooks/use-focus-fallback.ts index 06bd854e4fb69a..a9088aade9d96c 100644 --- a/packages/dataviews/src/hooks/use-focus-fallback.ts +++ b/packages/dataviews/src/hooks/use-focus-fallback.ts @@ -41,8 +41,11 @@ function getFallback( container: HTMLElement ) { ( element ) => element.tabIndex >= 0 && isVisible( element ) && - // The layout is inert while it loads, e.g. after an action. - ! element.closest( '[inert]' ) + // Usable, rather than disabled but still focusable. + ! element.matches( ':disabled, [aria-disabled="true"]' ) && + // Hidden on its own, like the table media, or inert while the + // layout loads, e.g. after an action. + ! element.closest( '[aria-hidden="true"], [inert]' ) ); return ( controls.find(