Skip to content

DataViews: Rename the bulk actions Cancel button to Clear selection - #87232

Open
HrithikDalal wants to merge 4 commits into
WordPress:trunkfrom
HrithikDalal:fix/dataviews-clear-selection-button
Open

HrithikDalal wants to merge 4 commits into
WordPress:trunkfrom
HrithikDalal:fix/dataviews-clear-selection-button

Conversation

@HrithikDalal

@HrithikDalal HrithikDalal commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What?

Part of #85052

The "Cancel" icon button at the end of the bulk actions toolbar is now a "Clear selection" text button, and it sits right after the actions instead of at the far end. When the text doesn't fit, it's an icon with a tooltip instead.

Why?

A close icon at the far end reads as closing the whole view, and "Cancel" doesn't say what gets cancelled. The text says it outright and sits next to the actions, where screen magnifier users will find it.

How?

  • The IconButton becomes a Button with the text "Clear selection", kept on one line.
  • Whether the text fits is measured on the toolbar, not the viewport, since it depends on the room the view and the actions leave (and on their translations). When it doesn't, e.g. at 320px next to the "Actions" menu, or in Trash with the sidebar open at around 800px, the CSS shows an icon with a tooltip and keeps the text as the button's name. It's the same button either way, so it keeps focus when the view resizes.
  • The disabled state and the onClearSelection focus handling from DataViews: Move bulk selection focus only on request from an interaction #86932 don't change.
  • The margin-inline-start: auto rule that pushed it to the end is gone.
  • Tests that found it by "Cancel" are updated, and a browser test checks the text/icon switch keeps the name and focus.

Testing Instructions

  1. Site Editor > Pages, table layout.
  2. Select a couple of rows. The toolbar shows a "Clear selection" text button right after the actions.
  3. Click it. The selection clears and focus goes back to the "Select all" checkbox, as before.
  4. Go to Trash, select pages and narrow the window. Once the text no longer fits, it turns into an icon with a "Clear selection" tooltip, and back to text when there's room. Focus stays on it if it had it.

Testing Instructions for Keyboard

Select rows with Space, Tab to "Clear selection" and press Enter. The selection clears.

Screenshots or screencast

Before After
clear-selection-before-full clear-selection-after-full

Use of AI Tools

Used Claude Code to co-author the fix. Reviewed and tested by me.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: HrithikDalal <hrithikd@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: fcoveram <fcoveram@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

}
};
const isMobile = useViewportMatch( 'medium', '<' );
const showClearSelectionText = useViewportMatch( 'large' );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we decide this on the width of the view rather than the viewport?

@oandregal oandregal Nov 25, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to that: why do we want to switch from text to button in smaller viewports? Can we keep the same?

Note that the current implementation also loses focus:

Screen.Recording.2026-11-25.at.12.03.18.mov

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points. It's one button now, text by default, so nothing gets swapped on resize and focus stays. It only turns into an icon (with a tooltip) when the text doesn't fit, which is measured on the toolbar instead of the viewport, so it follows the view's width and the length of the actions. E.g. at 320px next to the "Actions" menu the text got cut off, and in Trash with the sidebar it doesn't fit next to "Restore" and "Permanently delete" at around 800px. The text stays as its name either way.

@ntsekouras

Copy link
Copy Markdown
Contributor

Thanks for the PR! I think the main question here is text vs icon --cc @WordPress/gutenberg-design

@jasmussen

Copy link
Copy Markdown
Contributor

There's some precedence for "cancelling out" through closing modals, so a close icon can work for me. That's also in the light of the cancel button itself being a secondary affordance for clearing selections, with the primary being the top checkbox itself. These are not strong opinions, though, so I defer to tolks close to the dataviews metal on this. E.g. @verofasulo

@jameskoster

Copy link
Copy Markdown
Contributor

Moving the button closer to the bulk actions is a change I totally agree with. There may even be a case to put it immediately after the '4 items selected' text. Especially if we have designs to make that text a menu with options like 'Select this page', 'Select all'.

I can go either way on icon vs. text, but probably lean towards text because it's less ambiguous.

@fcoveram

Copy link
Copy Markdown
Contributor

+1 to show a text button at the end of the row

There may even be a case to put it immediately after the '4 items selected' text. Especially if we have designs to make that text a menu with options like 'Select this page', 'Select all'.

Not sure about this, as I think it's fair to assume that selecting entries intents to triggering an action on them. But the use case is not discarded for sure.

@HrithikDalal
HrithikDalal force-pushed the fix/dataviews-clear-selection-button branch from 461f337 to 45bb450 Compare November 27, 2026 09:10
@HrithikDalal

Copy link
Copy Markdown
Contributor Author

Thanks for the input everyone, went with text.

@github-actions
github-actions Bot requested review from aduth and ciampo November 27, 2026 09:10
@HrithikDalal
HrithikDalal force-pushed the fix/dataviews-clear-selection-button branch from 45bb450 to 991474c Compare December 3, 2026 04:10
Copilot AI balanced review requested due to automatic review settings December 3, 2026 04:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The pending toolbar freezes fit-dependent styling and tooltips during async bulk actions, causing text to overflow when the view narrows.

1 open issue
What changed in this PR

Clarifies DataViews’ bulk-selection control, addressing the ambiguous “Cancel” affordance tracked in #85052.

Changes:

  • Replaces “Cancel” with “Clear selection” beside the bulk actions.
  • Adds an icon-and-tooltip fallback when toolbar space is limited.
  • Updates tests and documents the change.
File Description
test/​e2e/​specs/​site-editor/​page-list.spec.js Updates the button locator.
packages/​dataviews/​src/​dataviews/​test/​dataviews.jsdom.test.tsx Updates selection-clearing tests.
packages/​dataviews/​src/​dataviews/​test/​bulk-selection.browser.test.tsx Checks responsive presentation, accessible name, and focus.
packages/​dataviews/​src/​components/​dataviews-bulk-actions/​style.scss Positions the control and styles its icon fallback.
packages/​dataviews/​src/​components/​dataviews-bulk-actions/​index.tsx Adds the renamed button and toolbar-fit measurement.
packages/​dataviews/​CHANGELOG.md Documents the enhancement and locator change.

Review effort: Balanced

paginationInfo.totalItems,
isMobile,
toolbarRefs,
isClearSelectionIconOnly,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. pendingContent now holds a function that takes the icon-only flag, so the toolbar shown while an action runs still switches between text and icon. Added a test that narrows the view while an action is pending.

@ciampo ciampo left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also prefer this new approach!

Comment on lines +17 to 19
// Like the actions, keep it on one line rather than letting it wrap and grow
// taller than the toolbar.
.dataviews-bulk-actions__clear {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The item count can still wrap, though. It's the only thing in the row that shrinks, so when space runs out it drops to two lines before the toolbar overflows, and "Clear selection" keeps its text the whole time. white-space: nowrap on .dataviews-bulk-actions-footer__item-count should make the button switch to the icon first.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. The count now stays on one line while "Clear selection" shows its text, so between about 340 and 360px it switches to the icon instead of wrapping. Once it's an icon the count can wrap again, otherwise the toolbar overflowed below 320px.

32
);

await page.viewport( 320, 900 );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would still pass with the old viewport check, since it shrinks the whole viewport. Could we keep the viewport wide and narrow just the DataViews container? That's the sidebar case this is really for.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to keep the viewport at 1280 and narrow a container around the DataViews to 340px. It also checks that the count stays on one line, so it fails without the nowrap too.

}, [] );
// Whenever the content may have changed, e.g. the actions or the count,
// and when the toolbar resizes.
useLayoutEffect( updateClearSelectionFit );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this measures on every render, including in the grid before anything is selected, when there's no clear button to fit. An early return when nothing's selected would skip that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an early return when there's no Clear selection button in the toolbar. I check the toolbar rather than selectedItems, since the toolbar shown while an action runs keeps its selection even when the items are already gone from data (e.g. after a trash).

@HrithikDalal
HrithikDalal force-pushed the fix/dataviews-clear-selection-button branch from 991474c to 4f2b3f6 Compare December 3, 2026 16:26

@ciampo ciampo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Comment on lines +471 to +474
useLayoutEffect( updateClearSelectionFit );
const resizeToolbarRef = useResizeObserver< HTMLDivElement >(
updateClearSelectionFit
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small edge case: this only re-measures after a render or when the toolbar resizes. If the text gets wider without either (say, a text-spacing bookmarklet or a late font load), the button stays as text and spills out of the toolbar. Maybe observe the count and actions too?

.toBe( 32 );
expect( count.getBoundingClientRect().height ).toBe( countHeight );
await expect.element( clear ).toHaveAccessibleName( 'Clear selection' );
await expect.element( clear ).toHaveFocus();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we widen the container back here and check the text comes back (with focus still on the button)? Might also be worth checking the icon is actually visible and the tooltip shows on hover. Right now an empty 32px box would still pass.

} }
/>
<Tooltip.Root disabled={ ! isClearSelectionIconOnly }>
<Tooltip.Trigger

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: IconButton also passes disabled to Tooltip.Trigger, so the tooltip stays closed while an action runs. Want to add disabled={ !! actionInProgress } here to match?

Comment on lines +449 to +468
const updateClearSelectionFit = useCallback( () => {
const toolbar = toolbarRef.current;
// Nothing to fit when nothing is selected. Checked on the toolbar, as
// the one shown while an action runs keeps its selection.
if ( ! toolbar?.querySelector( '.dataviews-bulk-actions__clear' ) ) {
return;
}
const wasIconOnly = toolbar.classList.contains(
'is-clear-selection-icon-only'
);
toolbar.classList.remove( 'is-clear-selection-icon-only' );
// Only a scroll container counts its end padding in `scrollWidth`.
const { overflow } = toolbar.style;
toolbar.style.overflow = 'hidden';
const isOverflowing = toolbar.scrollWidth > toolbar.clientWidth;
toolbar.style.overflow = overflow;
// Leave the class to the next render.
toolbar.classList.toggle( 'is-clear-selection-icon-only', wasIconOnly );
setIsClearSelectionIconOnly( isOverflowing );
}, [] );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't think useCallback does anything here. The layout effect has no deps, and useResizeObserver already wraps its callback in useEvent, so a plain function would do.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] DataViews /packages/dataviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants