Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/dataviews/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Enhancements

- 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)).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ 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,
useId,
useLayoutEffect,
useRef,
useState,
} from '@wordpress/element';
Expand Down Expand Up @@ -316,10 +318,32 @@ function ViewTable< Item >( {
const tableSelectionRef = useRef< HTMLSpanElement >( null );
const bulkSelectionRef = useRef< HTMLSpanElement >( null );
const bulkActionsRef = useRef< HTMLDivElement >( null );
// 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;
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 >(
syncBulkActionsPosition
);
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( syncBulkActionsPosition, [ showBulkActions ] );
const hadSelectionRef = useRef( false );
useEffect( () => {
const tableHead = tableHeaderRef.current;
Expand Down Expand Up @@ -453,6 +477,25 @@ function ViewTable< Item >( {

return (
<>
{ ( hasBulkActions || isActionInProgress ) && (
<div
className={ clsx(
'dataviews-view-table__bulk-actions-overlay',
{
'is-refreshing':
! isInfiniteScroll && isDelayedLoading,
}
) }
ref={ bulkActionsRef }
hidden={ ! showBulkActions }
inert={ inertValue( !! isLoading ) }
Comment thread
dinhtungdu marked this conversation as resolved.
Resolved
>
<BulkActionToolbar
onActionInProgressChange={ setIsActionInProgress }
selectionCheckboxRef={ bulkSelectionRef }
/>
</div>
) }
<table
className={ clsx( 'dataviews-view-table', className, {
[ `has-${ view.layout?.density }-density` ]:
Expand Down Expand Up @@ -504,7 +547,7 @@ function ViewTable< Item >( {
</Popover>
) }
<thead
ref={ tableHeaderRef }
ref={ tableHeaderRefs }
className={ clsx( {
'dataviews-view-table__thead--stuck':
isVerticallyScrolled,
Expand Down Expand Up @@ -640,29 +683,6 @@ function ViewTable< Item >( {
</th>
) }
</tr>
{ ( hasBulkActions || isActionInProgress ) && (
<tr
className="dataviews-view-table__bulk-actions-row"
hidden={ ! showBulkActions }
>
<td colSpan={ columnCount }>
<div
className="dataviews-view-table__bulk-actions-overlay"
ref={ bulkActionsRef }
inert={ inertValue( !! isLoading ) }
>
<BulkActionToolbar
onActionInProgressChange={
setIsActionInProgress
}
selectionCheckboxRef={
bulkSelectionRef
}
/>
</div>
</td>
</tr>
) }
</thead>
{ /* Render grouped data if groupBy is specified */ }
{ hasData && groupField && dataByGroup ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -345,26 +348,35 @@
.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;
z-index: 2;
position: sticky;
inset-block-start: 0;
inset-inline-start: 0;
z-index: 1;
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 {
// 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function PlanetOverview( { planets }: { planets: SpaceObject[] } ) {
</Card.Root>
</Stack>
</div>
<DataViews.Layout className={ styles.layout } />
<DataViews.Layout />
</>
);
}
Expand Down
4 changes: 0 additions & 4 deletions packages/dataviews/src/dataviews/stories/style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading