Repository navigation
DataViews: Rename the bulk actions Cancel button to Clear selection - #87232
HrithikDalal wants to merge 4 commits into
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. |
94fc5d8 to
461f337
Compare
| } | ||
| }; | ||
| const isMobile = useViewportMatch( 'medium', '<' ); | ||
| const showClearSelectionText = useViewportMatch( 'large' ); |
There was a problem hiding this comment.
Shouldn't we decide this on the width of the view rather than the viewport?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
|
Thanks for the PR! I think the main question here is text vs icon --cc @WordPress/gutenberg-design |
|
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 |
|
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. |
|
+1 to show a text button at the end of the row
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. |
461f337 to
45bb450
Compare
|
Thanks for the input everyone, went with text. |
45bb450 to
991474c
Compare
There was a problem hiding this comment.
🟡 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, |
There was a problem hiding this comment.
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.
| // Like the actions, keep it on one line rather than letting it wrap and grow | ||
| // taller than the toolbar. | ||
| .dataviews-bulk-actions__clear { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
…when the text doesn't fit
…on one line, and test a narrow view
…ays within narrow views
991474c to
4f2b3f6
Compare
| useLayoutEffect( updateClearSelectionFit ); | ||
| const resizeToolbarRef = useResizeObserver< HTMLDivElement >( | ||
| updateClearSelectionFit | ||
| ); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
| 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 ); | ||
| }, [] ); |
There was a problem hiding this comment.
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.

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?
IconButtonbecomes aButtonwith the text "Clear selection", kept on one line.onClearSelectionfocus handling from DataViews: Move bulk selection focus only on request from an interaction #86932 don't change.margin-inline-start: autorule that pushed it to the end is gone.Testing Instructions
Testing Instructions for Keyboard
Select rows with Space, Tab to "Clear selection" and press Enter. The selection clears.
Screenshots or screencast
Use of AI Tools
Used Claude Code to co-author the fix. Reviewed and tested by me.