Guidelines: Add data-slug attribute to settings list items#78676
Guidelines: Add data-slug attribute to settings list items#78676aagam-shah wants to merge 3 commits into
Conversation
Expose a stable per-section hook on the Guidelines settings list so an individual section can be targeted reliably by extensions, automation, and tests. The accordion refactor to CollapsibleCard (hashed CSS-module class names) and the content-guidelines -> guidelines rename left the section list items without any stable selector or element id. A `data-slug` attribute is resilient to styling/markup refactors and matches the convention WordPress core already uses to identify list items in wp-admin (e.g. theme cards carry `data-slug`). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
a828100 to
8814f77
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If 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. |
|
I'm not blocking this PR, but we need to use the accessible selector in our e2e testing. The need for the What problems are you currently experiencing? |
|
Thanks @t-hamano - agreed, e2e tests should use accessible selectors, and this isn't for that. This is really about restoring compatibility. Each section used to have a stable per-section The page itself is accessible (each section has an |
What?
Adds a
data-slugattribute to each guideline section<li>in the Guidelines settings page list (routes/guidelines/stage.tsx).Why?
The guideline section list items currently expose no stable way to identify an individual section from the markup:
content-guidelines__*class names were renamed toguidelines__*.CollapsibleCard, whose header/trigger uses hashed CSS-module class names (e.g._0625b55e82a0d93d__header-trigger) that change per build.id(previouslyguidelines-${slug}) was removed in that refactor.As a result there is no resilient selector for targeting a specific guideline section, which makes it hard for external code, extensions, automation, and e2e tests to reliably locate one. A
data-slugattribute is stable across styling/markup refactors and matches the convention WordPress core already uses to identify list items in wp-admin (e.g. theme cards in the theme browser carrydata-slug).How?
Adds
data-slug={ item.slug }to the list-item rendered fromGUIDELINE_ITEMSinstage.tsx. The slug values are the existing section identifiers (site,copy,images,blocks,additional).Testing Instructions
gutenberg-guidelinesexperiment.<li class="guidelines__list-item">now carriesdata-slug="<slug>".There is no visual change.
Screenshots or screencast
N/A — markup-only change, no visual impact.