Skip to content

Grid: preserve tile content semantics when dragging is disabled - #82511

Closed
chriskmnds wants to merge 3 commits into
WordPress:trunkfrom
chriskmnds:codex/grid-inactive-sortable-semantics
Closed

chriskmnds wants to merge 3 commits into
WordPress:trunkfrom
chriskmnds:codex/grid-inactive-sortable-semantics

Conversation

@chriskmnds

@chriskmnds chriskmnds commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

What?

Closes #82507.

Remove inactive drag-control semantics from tile content in DashboardGrid and DashboardLanes, including pinned items.

Why?

Read-mode and pinned tiles currently wrap their content in a focusable role="button" with aria-disabled="true". This gives enabled links, buttons and form controls a disabled semantic ancestor and introduces an inactive drag control in the tab order.

How?

Apply the sortable attributes only when dragging is enabled. Keep the existing listeners, refs, enabled activator and independent resize/action controls.

Update pinned-item and WidgetDashboard policy expectations, and add mounted tests for descendant semantics in both layouts, plus keyboard pickup, cancellation and focus for enabled drag controls and pinned resize handles. Move-denied widgets expose no drag activator while retaining permitted layout controls. Review should focus on the disabled wrapper semantics and preservation of permitted controls. Keyboard reorder completion in #82508 remains separate.

Testing Instructions

After rebasing onto trunk 980605ca93, all Grid and WidgetDashboard Vitest tests pass (252 tests), and changed-file lint passes. These focused checks ran on the available Node 24.12 environment with npm's engine gate bypassed because the host is below trunk's current Node 24.18 and npm 11.16 minimums; GitHub CI is validating the supported Node 24 and 26 matrix. Before the rebase, the previous head also passed the full production build and repository type check. The final Grid regression has four expected failures on unmodified wrappers and passes all eight cases with this change. These mounted JSDOM tests are complemented by fresh Chrome checks of both built layouts: native controls in read and pinned modes, enabled pickup/cancel with focus restoration, and pinned keyboard resizing. Full screen-reader qualification has not been performed.

  1. Run npm run test:unit:vitest -- packages/grid packages/widget-dashboard.
  2. Render the package-only fixture in Grid: inactive sortable wrappers give interactive widget content disabled button semantics #82507. Confirm that the link, button and select have no ancestor with disabled sortable-button semantics.
  3. Set editMode={ true } and add draggable: false to the layout item. Confirm that its content retains ordinary semantics and its resize handle remains available.
  4. Repeat with DashboardLanes.

Testing Instructions for Keyboard

  1. With editMode={ false }, Tab through the fixture. Focus should reach its native controls without stopping on an inactive drag wrapper. Activate Details with Enter, Refresh with Space, and change Metric with the arrow keys.
  2. Repeat with an item whose layout has draggable: false in edit mode. Its permitted resize control should remain reachable.
  3. Restore a draggable item in edit mode. Focus its drag activator, press Space to pick it up, and Escape to cancel. Confirm that focus remains on the activator.
  4. Repeat for both layouts.

Screenshots or screencast

This changes accessibility semantics without a visual layout change.

Use of AI Tools

I used OpenAI Codex to investigate, implement and test this change.

@chriskmnds
chriskmnds requested a review from retrofox as a code owner September 6, 2026 17:29
@github-actions github-actions Bot added [Package] Grid /packages/grid [Package] Widget Dashboard /packages/widget-dashboard labels Sep 6, 2026
@coderabbitai

coderabbitai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. To trigger a review, include @coderabbitai review in the PR description. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: ffc713bb-a438-41bc-951c-6fd8f0cdc308

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 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: chriskmnds <chriskmnds@git.wordpress.org>
Co-authored-by: adamwoodnz <adamwood@git.wordpress.org>

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

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.

@adamwoodnz

Copy link
Copy Markdown
Contributor

I rebased this on trunk (2fd8daed51) to resolve the conflicts: https://github.com/adamwoodnz/gutenberg/tree/rebase/grid-inactive-sortable-semantics

Conflicts resolved in the first commit:

To pick it up:

git fetch https://github.com/adamwoodnz/gutenberg.git rebase/grid-inactive-sortable-semantics
git reset --hard FETCH_HEAD
git push --force-with-lease

Testing

Node 24.18.0.

  • npm run test:unit:vitest -- packages/grid packages/widget-dashboard: 35 files, 299 tests pass.
  • Storybook, DashboardGrid and DashboardLanes:
Check Grid Lanes
Read mode: no sortable wrapper, no role="button" with aria-disabled, no extra tab stops ✅ ✅
Edit mode, draggable: false item: no wrapper or disabled ancestor around its content ✅ ✅
That item keeps its resize handle ✅ ✅
Draggable item: Space picks up, Escape cancels, focus stays on the activator ✅ ✅

For the draggable: false rows I added the flag to the first item of each EditMode story locally, since no story has a pinned item. The stories have no native controls inside tiles, so the Enter/Space/arrow key checks on links, buttons and selects are covered only by sortable-semantics.jsdom.test.tsx. No screen reader testing.

@adamwoodnz adamwoodnz 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.

Thanks @chriskmnds. This is a small, well-aimed fix: dropping the sortable attributes only when dragging is off removes the disabled role="button" ancestor and the dead tab stop, and keeps the enabled activator and resize handles as they were. The new sortable-semantics tests cover both layouts in read and pinned modes, with real links, buttons and a select inside the tile, which is the case that matters. The updated policy tests also check that the permitted controls stay enabled. I left one comment inline.

I reviewed the rebased branch from my earlier comment. The source change is the same as on this PR. I checked that no production code in grid or widget-dashboard depends on aria-roledescription="sortable" or aria-disabled on the activator, and that dnd-kit already returns listeners as undefined when disabled, so the activator div is inert in those modes.

Out of scope, for context: draggable tiles in edit mode still wrap their content in the role="button" activator (the nested-interactive issue noted on the EditMode stories, #81596).

@@ -0,0 +1,138 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

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 is a rendered test in jsdom, with a mocked ResizeObserver, fake timers and fireEvent key events. Trunk has been moving rendered Grid tests to Vitest Browser Mode (#80995, #82742). As a .browser.test.tsx, the Space/Escape pickup and focus checks would run against real events and layout, like keyboard-activation.browser.test.tsx. Not blocking.

@adamwoodnz

adamwoodnz commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Correction to my review: the jsdom test note is a blocker after the rebase, not a nit.

Trunk's Vitest migration (#82742) added a conventions check that runs in Static Checks. On the rebased branch, npm run test:unit:conventions fails:

packages/grid/src/shared/test/sortable-semantics.jsdom.test.tsx:36 layout, geometry, viewport, observer, animation, and scroll APIs require Browser Mode or an explicit jsdom exception with a concrete reason

Line 36 is the ResizeObserver stub. My earlier test results did not include this check.

I pushed a fix to the same branch (https://github.com/adamwoodnz/gutenberg/tree/rebase/grid-inactive-sortable-semantics, now at a37807a4ec). It moves the test to sortable-semantics.browser.test.tsx with the same cases, and uses real userEvent keys in place of the stub, fake timers and fireEvent. The reset commands in my first comment still apply.

On that commit, with Node 24.18.0:

  • npm run test:unit:conventions passes.
  • npm run test:unit:vitest -- packages/grid packages/widget-dashboard: 35 files, 299 tests pass, including the 8 moved cases.
  • ESLint on the new file passes.

I'm happy to raise a PR from my fork if you'd prefer I carry it from here, I don't mind either way 🙂

@adamwoodnz

Copy link
Copy Markdown
Contributor

@chriskmnds I opened #84869 from the rebased branch so it can go up for review. It has your change, the rebase conflict fixes and the Browser Mode test from my comments above, and it credits you. If you prefer to reset this branch and continue here, tell me and I will close mine.

adamwoodnz added a commit to adamwoodnz/gutenberg that referenced this pull request Oct 15, 2026
The CHANGELOG check requires the Unreleased entry to cite the PR that
carries it. The fix now lands through WordPress#84869, which supersedes WordPress#82511.
adamwoodnz added a commit to adamwoodnz/gutenberg that referenced this pull request Oct 19, 2026
The CHANGELOG check requires the Unreleased entry to cite the PR that
carries it. The fix now lands through WordPress#84869, which supersedes WordPress#82511.
adamwoodnz added a commit to adamwoodnz/gutenberg that referenced this pull request Oct 20, 2026
The CHANGELOG check requires the Unreleased entry to cite the PR that
carries it. The fix now lands through WordPress#84869, which supersedes WordPress#82511.
retrofox pushed a commit that referenced this pull request Oct 20, 2026
* Grid: preserve tile content semantics when dragging is disabled

* WidgetDashboard: update pinned policy tests for inactive drag semantics

* Grid: link changelog entry to pull request

* Grid: Move sortable semantics test to Browser Mode

Trunk's Vitest conventions check rejects jsdom tests that stub
observer APIs, so the `ResizeObserver` stub made Static Checks fail
after the rebase. In Browser Mode the test also uses real keyboard
events and focus in place of `fireEvent` and fake timers.

* Grid: Link changelog entry to #84869

The CHANGELOG check requires the Unreleased entry to cite the PR that
carries it. The fix now lands through #84869, which supersedes #82511.

* Grid: Move changelog entry to Unreleased

Grid 0.10.0 was released while this PR was open. The rebase applied
the entry cleanly inside the released 0.10.0 section, which would
have listed the fix under a version that does not include it.

* Grid: Say which tiles take keyboard focus in the README

Tiles are no longer focusable in read mode or when pinned, so the
keyboard steps apply only to draggable tiles in edit mode.

* Grid: Add stories for interactive tile content and pinned items

No story had native controls inside a tile or a pinned item, so the
a11y addon could not catch a regression of the drag wrapper around
them. The new stories open in read mode, where the addon runs, and
the EditMode stories now pin one tile.

* Grid: Say what the interactive content stories check

The stories open in read mode, where no tile is draggable, so the
"Draggable" labels misled readers. The descriptions now say that the
a11y addon is what checks the stories, and that the pinned tile only
matters in edit mode.

---------

Co-authored-by: Christos <chriskmnds@gmail.com>
@adamwoodnz

Copy link
Copy Markdown
Contributor

#84869 is merged and included your changes, you can close this.

@chriskmnds

Copy link
Copy Markdown
Contributor Author

#84869 is merged and included your changes, you can close this.

Thanks for following up @adamwoodnz. Good job. :-)

@chriskmnds chriskmnds closed this Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Grid /packages/grid [Package] Widget Dashboard /packages/widget-dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Grid: inactive sortable wrappers give interactive widget content disabled button semantics

2 participants