From ef50935b459ac3adc2f171dd8fed6a8ba815b8d1 Mon Sep 17 00:00:00 2001 From: Tung Du Date: Tue, 20 Oct 2026 18:44:36 +0700 Subject: [PATCH 01/10] refactor: render table bulk actions outside table Keep the toolbar over the sticky header without adding a table row or cell. Measure the header with the existing resize observer so density and custom header sizes stay aligned. Amp-Thread-ID: https://ampcode.com/threads/T-01a1590a-46c4-73eb-a596-5d55213f3f75 Co-authored-by: Amp --- packages/dataviews/CHANGELOG.md | 1 + .../dataviews-layouts/table/index.tsx | 59 +++++---- .../dataviews-layouts/table/style.scss | 28 ++--- .../test/bulk-selection.browser.test.tsx | 114 +++++++++++++++++- .../dataviews/test/dataviews.jsdom.test.tsx | 14 +-- 5 files changed, 169 insertions(+), 47 deletions(-) diff --git a/packages/dataviews/CHANGELOG.md b/packages/dataviews/CHANGELOG.md index 17f79c819e48ba..a38dfb6d6c1a62 100644 --- a/packages/dataviews/CHANGELOG.md +++ b/packages/dataviews/CHANGELOG.md @@ -8,6 +8,7 @@ ### Enhancements +- Render table bulk actions outside the table while preserving their placement over the column headers. - Use the design system outline for keyboard focus on list items ([#85358](https://github.com/WordPress/gutenberg/pull/85358)). - Simplify filter selection indicators and remove their hover colors ([#85191](https://github.com/WordPress/gutenberg/pull/85191)). diff --git a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx index e9c6e816bab42f..d10bec97b78272 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx @@ -2,6 +2,7 @@ import clsx from 'clsx'; import type { ComponentProps, CSSProperties, ReactElement } from 'react'; import { __, sprintf, isRTL } from '@wordpress/i18n'; import { Spinner as WCSpinner, Popover } from '@wordpress/components'; +import { useMergeRefs, useResizeObserver } from '@wordpress/compose'; import { useContext, useEffect, @@ -316,6 +317,14 @@ function ViewTable< Item >( { const tableSelectionRef = useRef< HTMLSpanElement >( null ); const bulkSelectionRef = useRef< HTMLSpanElement >( null ); const bulkActionsRef = useRef< HTMLDivElement >( null ); + const [ tableHeaderHeight, setTableHeaderHeight ] = useState( 52 ); + const resizeHeaderRef = useResizeObserver< HTMLTableSectionElement >( + ( [ entry ] ) => { + setTableHeaderHeight( entry.borderBoxSize[ 0 ].blockSize ); + }, + { box: 'border-box' } + ); + const tableHeaderRefs = useMergeRefs( [ tableHeaderRef, resizeHeaderRef ] ); const [ isActionInProgress, setIsActionInProgress ] = useState( false ); const hasBulkActions = useSomeItemHasAPossibleBulkAction( actions, data ); const showBulkActions = @@ -453,6 +462,31 @@ function ViewTable< Item >( { return ( <> + { ( hasBulkActions || isActionInProgress ) && ( + + ) } ( { ) } ( { ) } - { ( hasBulkActions || isActionInProgress ) && ( - - - - ) } { /* Render grouped data if groupBy is specified */ } { hasData && groupField && dataByGroup ? ( diff --git a/packages/dataviews/src/components/dataviews-layouts/table/style.scss b/packages/dataviews/src/components/dataviews-layouts/table/style.scss index 1a93ef06b7288e..5549da7cd7e97b 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/table/style.scss @@ -345,26 +345,24 @@ .dataviews-view-table.is-refreshing { @include dataviews-refreshing(); } -.dataviews-view-table .dataviews-view-table__bulk-actions-row { - height: 0; - border: 0; - - > td { - height: 0; - padding: 0; - } -} .dataviews-view-table__bulk-actions-overlay { - position: absolute; - inset: 0; + position: sticky; + inset-block-start: 0; + inset-inline-start: 0; z-index: 2; + height: 0; + flex-shrink: 0; > .dataviews-bulk-actions { - position: sticky; - inset-inline-start: 0; - width: 100cqi; - height: 100%; + position: absolute; + inset-inline: 0; + inset-block-start: 0; + height: var(--wp-dataviews-table-header-height); min-height: 0; } + + &.is-refreshing { + @include dataviews-refreshing(); + } } 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 2f7025fabd623f..c0782f276a8449 100644 --- a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx +++ b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx @@ -32,7 +32,7 @@ const actions: Action< Post >[] = [ { id: 'edit', label: 'Edit', supportsBulk: true, callback: () => {} }, ]; -function SelectableTable() { +function SelectableTable( { isLoading = false } = {} ) { const [ view, setView ] = useState< View >( { type: 'table', titleField: 'title', @@ -53,6 +53,7 @@ function SelectableTable() { view={ view } onChangeView={ setView } actions={ actions } + isLoading={ isLoading } paginationInfo={ paginationInfo } defaultLayouts={ { table: true } } /> @@ -125,6 +126,117 @@ it( 'keeps column names and sorting accessible during selection, skips covered c .not.toHaveAttribute( 'aria-sort' ); } ); +it( 'prevents table bulk actions from receiving focus while loading', async () => { + const { rerender } = await render( ); + const user = userEvent.setup(); + await user.click( + page.getByRole( 'checkbox', { name: 'Select all', exact: true } ) + ); + const cancel = page + .getByRole( 'button', { name: 'Cancel', exact: true } ) + .element(); + await rerender( ); + cancel.focus(); + expect( cancel ).not.toHaveFocus(); + await rerender( ); + cancel.focus(); + expect( cancel ).toHaveFocus(); +} ); + +it.each( [ 'balanced', 'compact', 'comfortable' ] as const )( + 'keeps the %s table toolbar aligned during scrolling and resizing', + async ( density ) => { + const data = Array.from( { length: 20 }, ( _, index ) => ( { + ...posts[ 0 ], + id: String( index ), + title: `Post ${ index }`, + } ) ); + await render( +
+ {} } + actions={ actions } + paginationInfo={ { + totalItems: data.length, + totalPages: 1, + } } + defaultLayouts={ { table: true } } + /> +
+ ); + const table = page.getByRole( 'table' ).element(); + const header = table.querySelector( 'thead' )!; + const scroller = table.parentElement!; + const firstRowTop = table + .querySelector( 'tbody' )! + .getBoundingClientRect().top; + const user = userEvent.setup(); + await user.click( + page.getByRole( 'checkbox', { name: 'Select all', exact: true } ) + ); + const toolbar = document.querySelector< HTMLDivElement >( + '.dataviews-bulk-actions' + )!; + expect( table ).not.toContainElement( toolbar ); + expect( + table.querySelector( 'tbody' )!.getBoundingClientRect().top + ).toBe( firstRowTop ); + + for ( const width of [ 1280, 390 ] ) { + await page.viewport( width, 900 ); + scroller.scrollTop = scroller.scrollHeight; + scroller.scrollLeft = scroller.scrollWidth; + expect( scroller.scrollTop ).toBeGreaterThan( 0 ); + expect( scroller.scrollLeft ).toBeGreaterThan( 0 ); + await expect + .poll( () => toolbar.getBoundingClientRect().height ) + .toBe( header.getBoundingClientRect().height ); + await expect + .poll( () => toolbar.getBoundingClientRect().top ) + .toBe( scroller.getBoundingClientRect().top ); + expect( toolbar.getBoundingClientRect().left ).toBe( + scroller.getBoundingClientRect().left + ); + expect( toolbar.getBoundingClientRect().width ).toBe( + scroller.clientWidth + ); + await expect + .element( + page.getByRole( 'button', { name: 'Cancel', exact: true } ) + ) + .toBeInViewport(); + } + + // Custom headers can change height after mount, independently of density. + header.style.height = '96px'; + await expect + .poll( () => toolbar.getBoundingClientRect().height ) + .toBe( 96 ); + await user.click( + page.getByRole( 'button', { name: 'Cancel', exact: true } ) + ); + await expect + .element( + page.getByRole( 'checkbox', { + name: 'Select all', + exact: true, + } ) + ) + .toHaveFocus(); + } +); + it( 'keeps a grid item checkbox below the sticky toolbar after arrow navigation and Tab', async () => { const data = Array.from( { length: 8 }, ( _, index ) => ( { ...posts[ 0 ], diff --git a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx index a0b7faf6c7649d..c18115ef5d5031 100644 --- a/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx +++ b/packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx @@ -163,7 +163,7 @@ vi.mock( import( '@wordpress/compose' ), async ( importOriginal ) => { setTimeout( () => { callback( [ { - borderBoxSize: [ { inlineSize: 500 } ], + borderBoxSize: [ { inlineSize: 500, blockSize: 48 } ], }, ] ); }, 0 ); @@ -302,7 +302,7 @@ describe( 'DataViews component', () => { expect( callback ).not.toHaveBeenCalled(); } ); - it( 'moves default table bulk actions into the header and preserves focus', async () => { + it( 'shows bulk actions outside the table without adding rows and preserves focus', async () => { render( ); expect( screen.getByText( '3 items' ) ).toBeInTheDocument(); expect( @@ -317,9 +317,9 @@ describe( 'DataViews component', () => { const tableHeader = within( screen.getByRole( 'table' ) ).getAllByRole( 'rowgroup' )[ 0 ]; - const toolbarCell = within( tableHeader ).getByRole( 'cell', { - name: /3 items selected/, - } ); + const toolbar = getBulkActionToolbar(); + expect( screen.getByRole( 'table' ) ).not.toContainElement( toolbar ); + expect( within( tableHeader ).getAllByRole( 'row' ) ).toHaveLength( 1 ); const titleHeader = within( tableHeader ).getByRole( 'columnheader', { name: 'Title', } ); @@ -327,7 +327,7 @@ describe( 'DataViews component', () => { within( titleHeader ).getByRole( 'button', { hidden: true } ) ).toHaveAttribute( 'inert' ); expect( - within( toolbarCell ).getByRole( 'checkbox', { + within( toolbar ).getByRole( 'checkbox', { name: 'Deselect all', } ) ).toHaveFocus(); @@ -336,7 +336,7 @@ describe( 'DataViews component', () => { ).toBeInTheDocument(); await user.click( - within( toolbarCell ).getByRole( 'button', { name: 'Cancel' } ) + within( toolbar ).getByRole( 'button', { name: 'Cancel' } ) ); expect( within( titleHeader ).getByRole( 'button' ) ).toBeEnabled(); expect( From d9278465f2d42e6b81c5782cc0ff10385cd2bc48 Mon Sep 17 00:00:00 2001 From: Tung Du Date: Wed, 21 Oct 2026 11:55:18 +0700 Subject: [PATCH 02/10] fix: keep table toolbar backing opaque while refreshing Fade the toolbar over a themed backing so covered column headers cannot show through. Extend delayed-loading browser coverage. Amp-Thread-ID: https://ampcode.com/threads/T-01a1590a-46c4-73eb-a596-5d55213f3f75 Co-authored-by: Amp --- .../dataviews-layouts/table/style.scss | 13 +++++++++- .../test/bulk-selection.browser.test.tsx | 26 ++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-layouts/table/style.scss b/packages/dataviews/src/components/dataviews-layouts/table/style.scss index 5549da7cd7e97b..48aa4507afff87 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/table/style.scss @@ -363,6 +363,17 @@ } &.is-refreshing { - @include dataviews-refreshing(); + // Keep covered headers behind an opaque surface while the toolbar fades. + &::before { + content: ""; + position: absolute; + inset: 0; + height: var(--wp-dataviews-table-header-height); + background: var(--wp-dataviews-color-background, var(--wpds-color-background-surface-neutral-strong)); + } + + > .dataviews-bulk-actions { + @include dataviews-refreshing(); + } } } 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 c0782f276a8449..f987d1b312e7d4 100644 --- a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx +++ b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx @@ -126,7 +126,7 @@ it( 'keeps column names and sorting accessible during selection, skips covered c .not.toHaveAttribute( 'aria-sort' ); } ); -it( 'prevents table bulk actions from receiving focus while loading', async () => { +it( 'keeps loading bulk actions unfocusable over an opaque backing', async () => { const { rerender } = await render( ); const user = userEvent.setup(); await user.click( @@ -135,9 +135,33 @@ it( 'prevents table bulk actions from receiving focus while loading', async () = const cancel = page .getByRole( 'button', { name: 'Cancel', exact: true } ) .element(); + const table = page.getByRole( 'table' ).element(); + const toolbar = document.querySelector( '.dataviews-bulk-actions' )!; + const overlay = toolbar.parentElement!; await rerender( ); cancel.focus(); expect( cancel ).not.toHaveFocus(); + await expect + .poll( () => { + const style = getComputedStyle( table ); + return ( + style.animationName !== 'none' || Number( style.opacity ) < 1 + ); + } ) + .toBe( true ); + expect( getComputedStyle( overlay ).opacity ).toBe( '1' ); + expect( getComputedStyle( overlay ).animationName ).toBe( 'none' ); + const toolbarStyle = getComputedStyle( toolbar ); + expect( + toolbarStyle.animationName !== 'none' || + Number( toolbarStyle.opacity ) < 1 + ).toBe( true ); + const backing = getComputedStyle( overlay, '::before' ); + expect( backing.content ).toBe( '""' ); + expect( backing.backgroundColor ).toBe( + getComputedStyle( toolbar ).backgroundColor + ); + expect( backing.backgroundColor ).not.toBe( 'rgba(0, 0, 0, 0)' ); await rerender( ); cancel.focus(); expect( cancel ).toHaveFocus(); From aeb2ced1f01248829f414299cfd34402d6efa307 Mon Sep 17 00:00:00 2001 From: Tung Du Date: Wed, 21 Oct 2026 13:13:39 +0700 Subject: [PATCH 03/10] test: align toolbar checks with sibling placement Cover fractional scroll bounds, locate bulk actions outside table cells, and link the changelog to this PR. Amp-Thread-ID: https://ampcode.com/threads/T-01a1590a-46c4-73eb-a596-5d55213f3f75 Co-authored-by: Amp --- packages/dataviews/CHANGELOG.md | 2 +- .../dataviews/test/bulk-selection.browser.test.tsx | 12 ++++++++---- test/e2e/specs/site-editor/page-list.spec.js | 4 +--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/dataviews/CHANGELOG.md b/packages/dataviews/CHANGELOG.md index a38dfb6d6c1a62..a2db9e8afb1fe2 100644 --- a/packages/dataviews/CHANGELOG.md +++ b/packages/dataviews/CHANGELOG.md @@ -8,7 +8,7 @@ ### Enhancements -- Render table bulk actions outside the table while preserving their placement over the column headers. +- Render table bulk actions outside the table while preserving their placement over the column headers ([#85250](https://github.com/WordPress/gutenberg/pull/85250)). - Use the design system outline for keyboard focus on list items ([#85358](https://github.com/WordPress/gutenberg/pull/85358)). - Simplify filter selection indicators and remove their hover colors ([#85191](https://github.com/WordPress/gutenberg/pull/85191)). 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 f987d1b312e7d4..b15b53bbcdec10 100644 --- a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx +++ b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx @@ -186,7 +186,7 @@ it.each( [ 'balanced', 'compact', 'comfortable' ] as const )( fields: [ 'author' ], layout: { density, - styles: { author: { minWidth: '1400px' } }, + styles: { author: { minWidth: '1400.625px' } }, }, } } onChangeView={ () => {} } @@ -229,9 +229,13 @@ it.each( [ 'balanced', 'compact', 'comfortable' ] as const )( await expect .poll( () => toolbar.getBoundingClientRect().top ) .toBe( scroller.getBoundingClientRect().top ); - expect( toolbar.getBoundingClientRect().left ).toBe( - scroller.getBoundingClientRect().left - ); + // Scroll extents round to whole pixels, unlike fractional sticky bounds. + expect( + Math.abs( + toolbar.getBoundingClientRect().left - + scroller.getBoundingClientRect().left + ) + ).toBeLessThanOrEqual( 0.5 ); expect( toolbar.getBoundingClientRect().width ).toBe( scroller.clientWidth ); diff --git a/test/e2e/specs/site-editor/page-list.spec.js b/test/e2e/specs/site-editor/page-list.spec.js index 26caa080b6dc45..b6168f82aa6a1e 100644 --- a/test/e2e/specs/site-editor/page-list.spec.js +++ b/test/e2e/specs/site-editor/page-list.spec.js @@ -592,9 +592,7 @@ test.describe( 'Page List', () => { await table.getByRole( 'checkbox', { name: 'Select all' } ).click(); // The extensible site editor keeps the selection in the URL, so // the checkbox only flips once the route has re-rendered. - const bulkActions = table.getByRole( 'cell', { - name: /items selected/, - } ); + const bulkActions = page.locator( '.dataviews-bulk-actions' ); await expect( bulkActions.getByRole( 'checkbox', { name: 'Deselect all' } ) ).toBeChecked(); From dd2b7be165009cd9aedb473a2741d468ee935c73 Mon Sep 17 00:00:00 2001 From: Tung Du Date: Wed, 21 Oct 2026 20:19:59 +0700 Subject: [PATCH 04/10] test: clarify bulk actions loading test name Amp-Thread-ID: https://ampcode.com/threads/T-01a1590a-46c4-73eb-a596-5d55213f3f75 Co-authored-by: Amp --- .../src/dataviews/test/bulk-selection.browser.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b15b53bbcdec10..e33a7f65f3beb4 100644 --- a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx +++ b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx @@ -126,7 +126,7 @@ it( 'keeps column names and sorting accessible during selection, skips covered c .not.toHaveAttribute( 'aria-sort' ); } ); -it( 'keeps loading bulk actions unfocusable over an opaque backing', async () => { +it( 'blocks focus on bulk actions and covers column headings while loading', async () => { const { rerender } = await render( ); const user = userEvent.setup(); await user.click( From 419a6be207f6952cfc867258ff66e0853fa64f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Fri, 23 Oct 2026 10:55:40 +0200 Subject: [PATCH 05/10] fix: size table toolbar to the header before the first paint The header height lived in React state seeded with 52px and updated from the resize observer, which reports after the first paint. Toolbars shown on mount (such as a selection restored from the URL) rendered at 52px for a frame in every density. Measure the header in a layout effect when the toolbar shows, and write the height to the overlay directly from the observer so header resizes no longer re-render the table. Co-Authored-By: Claude Opus 5.5 --- .../dataviews-layouts/table/index.tsx | 26 ++++++---- .../test/bulk-selection.browser.test.tsx | 47 ++++++++++++++++++- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx index d10bec97b78272..c9a69b9884d210 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx @@ -7,6 +7,7 @@ import { useContext, useEffect, useId, + useLayoutEffect, useRef, useState, } from '@wordpress/element'; @@ -317,18 +318,28 @@ function ViewTable< Item >( { const tableSelectionRef = useRef< HTMLSpanElement >( null ); const bulkSelectionRef = useRef< HTMLSpanElement >( null ); const bulkActionsRef = useRef< HTMLDivElement >( null ); - const [ tableHeaderHeight, setTableHeaderHeight ] = useState( 52 ); + // Size the bulk actions toolbar to the header by writing to the DOM + // directly: it is correct on first paint and skips a re-render. + const syncBulkActionsHeight = () => { + const header = tableHeaderRef.current; + const overlay = bulkActionsRef.current; + if ( header && overlay ) { + overlay.style.setProperty( + '--wp-dataviews-table-header-height', + `${ header.getBoundingClientRect().height }px` + ); + } + }; const resizeHeaderRef = useResizeObserver< HTMLTableSectionElement >( - ( [ entry ] ) => { - setTableHeaderHeight( entry.borderBoxSize[ 0 ].blockSize ); - }, - { box: 'border-box' } + syncBulkActionsHeight ); const tableHeaderRefs = useMergeRefs( [ tableHeaderRef, resizeHeaderRef ] ); const [ isActionInProgress, setIsActionInProgress ] = useState( false ); const hasBulkActions = useSomeItemHasAPossibleBulkAction( actions, data ); const showBulkActions = ( hasBulkActions && selection.length > 0 ) || isActionInProgress; + // The resize observer reports after the first paint, so measure on show. + useLayoutEffect( syncBulkActionsHeight, [ showBulkActions ] ); const hadSelectionRef = useRef( false ); useEffect( () => { const tableHead = tableHeaderRef.current; @@ -475,11 +486,6 @@ function ViewTable< Item >( { hidden={ ! showBulkActions } inert={ inertValue( !! isLoading ) } aria-busy={ isLoading } - style={ - { - '--wp-dataviews-table-header-height': `${ tableHeaderHeight }px`, - } as CSSProperties - } > { + const heights: Array< { toolbar: number; header: number } > = []; + // Layout effects of a later sibling run after the table commits and + // before the browser paints, so this records the first painted frame. + function MeasureFirstFrame() { + useLayoutEffect( () => { + heights.push( { + toolbar: document + .querySelector( '.dataviews-bulk-actions' )! + .getBoundingClientRect().height, + header: document + .querySelector( 'thead' )! + .getBoundingClientRect().height, + } ); + }, [] ); + return null; + } + await render( + <> + {} } + actions={ actions } + selection={ [ '1' ] } + onChangeSelection={ () => {} } + paginationInfo={ { totalItems: 2, totalPages: 1 } } + defaultLayouts={ { table: true } } + /> + + + ); + expect( heights ).toHaveLength( 1 ); + expect( heights[ 0 ].toolbar ).toBe( heights[ 0 ].header ); + } +); + it( 'keeps a grid item checkbox below the sticky toolbar after arrow navigation and Tab', async () => { const data = Array.from( { length: 8 }, ( _, index ) => ( { ...posts[ 0 ], From 23e993ecb4ff32b4bd03a86d4e55763722eb45a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Fri, 23 Oct 2026 11:16:38 +0200 Subject: [PATCH 06/10] fix: keep table toolbar over an offset header and below page layers The toolbar now sits outside the table, so a sticky offset that consumers give the header no longer moved it: it stayed at the top of the scroll area while the header sat lower. Copy the header's computed inset-block-start onto the toolbar when it is placed. Its z-index of 2 also lifted it above page elements at z-index 2 (such as a sticky heading), which the header-contained toolbar stayed under. Isolate the table so the header's z-index stays inside it, and drop the toolbar back to z-index 1. Co-Authored-By: Claude Opus 5.5 --- .../dataviews-layouts/table/index.tsx | 16 ++-- .../dataviews-layouts/table/style.scss | 5 +- .../test/bulk-selection.browser.test.tsx | 80 +++++++++++++++++++ 3 files changed, 94 insertions(+), 7 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx index c9a69b9884d210..7c133c305070e1 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx @@ -318,20 +318,24 @@ function ViewTable< Item >( { const tableSelectionRef = useRef< HTMLSpanElement >( null ); const bulkSelectionRef = useRef< HTMLSpanElement >( null ); const bulkActionsRef = useRef< HTMLDivElement >( null ); - // Size the bulk actions toolbar to the header by writing to the DOM - // directly: it is correct on first paint and skips a re-render. - const syncBulkActionsHeight = () => { + // Place the bulk actions toolbar over the header by writing to the DOM + // directly: it is correct on first paint and skips a re-render. The sticky + // offset is copied so the toolbar follows a header that consumers move. + const syncBulkActionsPosition = () => { const header = tableHeaderRef.current; const overlay = bulkActionsRef.current; - if ( header && overlay ) { + const win = header?.ownerDocument.defaultView; + if ( header && overlay && win ) { overlay.style.setProperty( '--wp-dataviews-table-header-height', `${ header.getBoundingClientRect().height }px` ); + overlay.style.insetBlockStart = + win.getComputedStyle( header ).insetBlockStart; } }; const resizeHeaderRef = useResizeObserver< HTMLTableSectionElement >( - syncBulkActionsHeight + syncBulkActionsPosition ); const tableHeaderRefs = useMergeRefs( [ tableHeaderRef, resizeHeaderRef ] ); const [ isActionInProgress, setIsActionInProgress ] = useState( false ); @@ -339,7 +343,7 @@ function ViewTable< Item >( { const showBulkActions = ( hasBulkActions && selection.length > 0 ) || isActionInProgress; // The resize observer reports after the first paint, so measure on show. - useLayoutEffect( syncBulkActionsHeight, [ showBulkActions ] ); + useLayoutEffect( syncBulkActionsPosition, [ showBulkActions ] ); const hadSelectionRef = useRef( false ); useEffect( () => { const tableHead = tableHeaderRef.current; diff --git a/packages/dataviews/src/components/dataviews-layouts/table/style.scss b/packages/dataviews/src/components/dataviews-layouts/table/style.scss index 48aa4507afff87..c0e74526c461fb 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/style.scss +++ b/packages/dataviews/src/components/dataviews-layouts/table/style.scss @@ -7,6 +7,9 @@ border-color: inherit; border-collapse: collapse; position: relative; + // Keep the sticky header's z-index inside the table, so the bulk actions + // toolbar (a sibling) covers it without rising above the page's own layers. + isolation: isolate; color: var(--wpds-color-foreground-content-neutral-weak); margin-bottom: auto; background-color: inherit; @@ -350,7 +353,7 @@ position: sticky; inset-block-start: 0; inset-inline-start: 0; - z-index: 2; + z-index: 1; height: 0; flex-shrink: 0; 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 9f828cde28d84a..3fcf4f2bbb29c0 100644 --- a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx +++ b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx @@ -310,6 +310,86 @@ it.each( [ 'balanced', 'compact', 'comfortable' ] as const )( } ); +it( 'keeps the table toolbar over a header that consumers offset', async () => { + const data = Array.from( { length: 20 }, ( _, index ) => ( { + ...posts[ 0 ], + id: String( index ), + title: `Post ${ index }`, + } ) ); + await render( +
+ + {} } + actions={ actions } + paginationInfo={ { totalItems: data.length, totalPages: 1 } } + defaultLayouts={ { table: true } } + > + + +
+ ); + await userEvent.click( + page.getByRole( 'checkbox', { name: 'Select all', exact: true } ) + ); + const header = document.querySelector( 'thead' )!; + const toolbar = document.querySelector( '.dataviews-bulk-actions' )!; + const scroller = document.querySelector( '.dataviews-layout__container' )!; + for ( const scrollTop of [ 0, scroller.scrollHeight ] ) { + scroller.scrollTop = scrollTop; + await expect + .poll( () => toolbar.getBoundingClientRect().top ) + .toBe( header.getBoundingClientRect().top ); + } +} ); + +it( 'keeps the table toolbar below sticky page elements', async () => { + const data = Array.from( { length: 20 }, ( _, index ) => ( { + ...posts[ 0 ], + id: String( index ), + title: `Post ${ index }`, + } ) ); + await render( + <> +
+ {} } + actions={ actions } + paginationInfo={ { totalItems: data.length, totalPages: 1 } } + defaultLayouts={ { table: true } } + /> + + ); + await userEvent.click( + page.getByRole( 'checkbox', { name: 'Select all', exact: true } ) + ); + const toolbar = document.querySelector( '.dataviews-bulk-actions' )!; + // Scroll the page so the toolbar passes under the sticky heading. + window.scrollBy( 0, toolbar.getBoundingClientRect().top - 20 ); + const { left, width } = toolbar.getBoundingClientRect(); + await expect + .poll( () => document.elementFromPoint( left + width / 2, 40 ) ) + .toBe( page.getByTestId( 'page-heading' ).element() ); + window.scrollTo( 0, 0 ); +} ); + it( 'keeps a grid item checkbox below the sticky toolbar after arrow navigation and Tab', async () => { const data = Array.from( { length: 8 }, ( _, index ) => ( { ...posts[ 0 ], From 5b680c0f6982f062771a23965eda392d84e033e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Fri, 23 Oct 2026 11:16:55 +0200 Subject: [PATCH 07/10] Storybook: drop the broken table header offset in Free Composition The story offset the sticky table header by 67px to clear its sticky heading, but the header sticks inside the layout's own scroll area, which never scrolls in this story. The header never stuck to the page and instead sat 67px down, covering the first row. Co-Authored-By: Claude Opus 5.5 --- packages/dataviews/src/dataviews/stories/free-composition.tsx | 2 +- packages/dataviews/src/dataviews/stories/style.module.css | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/dataviews/src/dataviews/stories/free-composition.tsx b/packages/dataviews/src/dataviews/stories/free-composition.tsx index 8d556678f640ad..f976f941d97fe7 100644 --- a/packages/dataviews/src/dataviews/stories/free-composition.tsx +++ b/packages/dataviews/src/dataviews/stories/free-composition.tsx @@ -95,7 +95,7 @@ function PlanetOverview( { planets }: { planets: SpaceObject[] } ) {
- + ); } diff --git a/packages/dataviews/src/dataviews/stories/style.module.css b/packages/dataviews/src/dataviews/stories/style.module.css index 8787ea479818da..653d9185a30add 100644 --- a/packages/dataviews/src/dataviews/stories/style.module.css +++ b/packages/dataviews/src/dataviews/stories/style.module.css @@ -10,10 +10,6 @@ background-color: #fff; } -.layout:global(.dataviews-view-table) thead { - inset-block-start: 67px; -} - .empty { border: 1px solid #000; border-radius: 8px; From 8872d9d893505070a068ad1e09b6863cf8cb4930 Mon Sep 17 00:00:00 2001 From: Tung Du Date: Mon, 26 Oct 2026 10:17:28 +0700 Subject: [PATCH 08/10] test: locate bulk actions by role Amp-Thread-ID: https://ampcode.com/threads/T-01a1590a-46c4-73eb-a596-5d55213f3f75 Co-authored-by: Amp --- test/e2e/specs/site-editor/page-list.spec.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/e2e/specs/site-editor/page-list.spec.js b/test/e2e/specs/site-editor/page-list.spec.js index b6168f82aa6a1e..e539d2b26da2c6 100644 --- a/test/e2e/specs/site-editor/page-list.spec.js +++ b/test/e2e/specs/site-editor/page-list.spec.js @@ -592,12 +592,14 @@ test.describe( 'Page List', () => { await table.getByRole( 'checkbox', { name: 'Select all' } ).click(); // The extensible site editor keeps the selection in the URL, so // the checkbox only flips once the route has re-rendered. - const bulkActions = page.locator( '.dataviews-bulk-actions' ); await expect( - bulkActions.getByRole( 'checkbox', { name: 'Deselect all' } ) + page.getByRole( 'checkbox', { + name: 'Deselect all', + exact: true, + } ) ).toBeChecked(); - await bulkActions - .getByRole( 'button', { name: 'Bulk edit' } ) + await page + .getByRole( 'button', { name: 'Bulk edit', exact: true } ) .click(); const modal = page.locator( '.dataviews-action-modal__quick-edit' ); From 993b190f62119649e9aa2ebb70a4194f7c91bb6f Mon Sep 17 00:00:00 2001 From: Tung Du Date: Mon, 26 Oct 2026 10:22:39 +0700 Subject: [PATCH 09/10] fix: remove redundant bulk toolbar busy state Amp-Thread-ID: https://ampcode.com/threads/T-01a1590a-46c4-73eb-a596-5d55213f3f75 Co-authored-by: Amp --- .../dataviews/src/components/dataviews-layouts/table/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx index 7c133c305070e1..7c790ae69e060d 100644 --- a/packages/dataviews/src/components/dataviews-layouts/table/index.tsx +++ b/packages/dataviews/src/components/dataviews-layouts/table/index.tsx @@ -489,7 +489,6 @@ function ViewTable< Item >( { ref={ bulkActionsRef } hidden={ ! showBulkActions } inert={ inertValue( !! isLoading ) } - aria-busy={ isLoading } > Date: Mon, 26 Oct 2026 11:01:18 +0700 Subject: [PATCH 10/10] test: tolerate rounded bulk toolbar width Amp-Thread-ID: https://ampcode.com/threads/T-01a1590a-46c4-73eb-a596-5d55213f3f75 Co-authored-by: Amp --- .../src/dataviews/test/bulk-selection.browser.test.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 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 3fcf4f2bbb29c0..9b03ad99e3fd27 100644 --- a/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx +++ b/packages/dataviews/src/dataviews/test/bulk-selection.browser.test.tsx @@ -236,9 +236,11 @@ it.each( [ 'balanced', 'compact', 'comfortable' ] as const )( scroller.getBoundingClientRect().left ) ).toBeLessThanOrEqual( 0.5 ); - expect( toolbar.getBoundingClientRect().width ).toBe( - scroller.clientWidth - ); + expect( + Math.abs( + toolbar.getBoundingClientRect().width - scroller.clientWidth + ) + ).toBeLessThanOrEqual( 0.5 ); await expect .element( page.getByRole( 'button', { name: 'Cancel', exact: true } )