feat(accordion): open accordion item from URL hash - #2664
Open
faisalahammad wants to merge 1 commit into
Open
Conversation
Adds a frontend script that reads window.location.hash on page load, slugifies the hash and each accordion item's summary title, then opens and scrolls into view the single matching item. - src/js/coblocks-accordion-script.js: hash-driven open + scroll - src/js/test/coblocks-accordion-script.spec.js: jsdom smoke tests - webpack.config.js: add entry for the new script - includes/class-coblocks-block-assets.php: register + conditional enqueue via render_block filter Script only loads on pages that render coblocks/accordion or coblocks/accordion-item. Ambiguous matches (0 or 2+) are safely ignored. Works with the native details toggle path and the existing IE polyfill. Fixes godaddy-wordpress#2663
faisalahammad
force-pushed
the
fix/2663-accordion-deep-link
branch
from
July 30, 2026 10:56
8f4130b to
1b16716
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a small client-side helper that opens and scrolls to an accordion item whose title matches
window.location.hashon page load. Visiting/page#title-aopens the item titled "Title A" and scrolls it into the viewport.No saved markup change, no editor change: the existing
<details>/<summary>HTML stays byte-for-byte identical. The script is enqueued only on pages that rendercoblocks/accordionorcoblocks/accordion-itemvia the existingrender_blockfilter inclass-coblocks-block-assets.php.Behaviour:
Title A→title-a, lowercase, non-alphanumeric collapsed to-+)..wp-block-coblocks-accordion-item__titlesummaries across all accordions on the page.details.open = trueand theopenattribute so the native<details>toggle AND the IE polyfill (which observesgetAttribute('open')) pick it up, then scrolls it into view.(prefers-reduced-motion: reduce).decodeURIComponentis wrapped in try/catch so malformed percent-encoding never throws.Closes #2663
Screenshots
Not applicable — no visible UI change to existing markup.
Types of changes
How has this been tested?
Automated:
yarn test:js— 23/23 pass ontestPathPattern=accordion, including the 10 new jsdom smoke tests (no-hash, bare-hash, single-match, slug-with-punctuation, missing-hash, duplicate-slug guard, reduced-motion, empty-DOM, IE-polyfill attribute set).src/blocks/accordion/test/save.spec.js,src/blocks/accordion/accordion-item/test/save.spec.js,src/blocks/accordion/test/transforms.spec.js.Manual (see TESTING_INSTRUCTIONS.md in the branch):
/page#title-b— item B opens and the page scrolls so its summary is at viewport top./page#bogus— nothing changes, no console errors.coblocks-accordion-script.jsscript tag.Acceptance criteria
User can deep-link to a specific accordion item by appending the slugified title to the URL hash, and the item opens and scrolls into view on load. No regression to existing accordion behaviour or saved markup.
Checklist: