PRC's override/extension of the WordPress core/details block, branded as "Collapsible" in the editor.
prc-block/core-details
Target Block: core/details
- Replaces native browser disclosure markers with custom FontAwesome caret icons (prevents iOS Safari emoji glyph fallback)
- Adds "Plus/Minus Icon" and "Knight Co-Branded" block styles
- Adds "close when focus lost" behavior via the Interactivity API
- Syncs Entity as Iframe blocks inside the panel with the
<details open>state (lazy iframesrc+ resizer when expanded) - Provides Pew-Knight Initiative co-branded collapsible with logo and link-to-collection behavior
- Registers block variations ("Collapsible" and "Pew Knight Co-Branded") with pre-configured styling
- Adds transforms from the legacy
prc-block/collapsibleblock
| Support | Value |
|---|---|
interactivity |
true (defined in block.json) |
| Attribute | Type | Default | Description |
|---|---|---|---|
closeWhenFocusLost |
boolean |
false |
Automatically close the details element when clicking outside |
Registered via block_type_metadata filter.
| Style Name | Label | Description |
|---|---|---|
plus-icon |
Plus/Minus Icon | Replaces caret with circle-plus/circle-minus icons, bold summary text |
pew-knight-co-branded |
Knight Co-Branded | Displays Pew-Knight Initiative logo in summary, hides text, uses plus/minus icons. Supports dark mode with alternate logo. |
Both styles inject inline CSS with data URI icon references.
Base icon styles (applied globally to all core/details):
- Removes native
list-styleand::-webkit-details-marker - Adds a caret-down
::afterpseudo-element on summary - Swaps to caret-up when
[open]
Dark mode (caret icons): style.scss compiles to style-index.css and is registered via block.json (style). Core_Details enqueues that stylesheet on the frontend (with the global icon inline CSS) and in the block editor. For users in dark mode (prefers-color-scheme: dark) while logged in (body.logged-in, consistent with the Knight co-branded dark logo), the summary ::after caret uses filter: invert(1) so black SVG data-URI icons read correctly on dark UI.
From editor.scss:
- Resets color and background inheritance for the editor wrapper
From style.scss (built as style-index.css):
- Dark-mode inversion for the default disclosure caret on
summary::after(see above)
From index.jsx and controls.jsx:
- Wraps the block edit with a "Details Settings" Inspector panel
- Provides a
ToggleControlfor the "Close when focus lost" attribute - Registers block variations and transforms on load
From view.js:
Extends the core/details Interactivity API store with two actions:
-
actions.handleOutsideClick: WhencloseWhenFocusLostis enabled, listens for document-level clicks and closes the details element if the click target is outside it. UseswithSyncEventfor synchronous event handling. -
actions.handleSummaryClick: For Knight Co-Branded style, detects clicks within the logo zone (first 183px of the summary element). If clicked in the logo zone, prevents the default toggle behavior and opens the Pew-Knight Initiative collection URL in a new tab. Supports RTL layouts.
Entity as Iframe (same core/details store):
When the rendered block contains an Entity as Iframe block, PHP adds:
data-wp-contextincludesisOpen(initial value from the server-renderedopenattribute).data-wp-on--toggle="actions.syncDetailsOpenFromToggle"on<details>socontext.isOpenstays aligned with the native open state.data-wp-watch--sync-entity-iframes="callbacks.syncEntityIframeWithDetails"so nested entity iframeisActivetrackscontext.isOpen(lazy iframesrc+ resizer when expanded).data-wp-on--pointerenter="callbacks.prefetchEntityIframeOnSummaryPointer"on<summary>for best-effort prefetch ofdata-entity-iframe-prefetch-urlbefore first open.
Context passed via data-wp-context (examples):
{
"closeWhenFocusLost": true,
"knightCollectionUrl": "https://www.pewresearch.org/collections/pew-knight-initiative/",
"isOpen": false
}When only entity iframe is enabled (no focus-lost, no Knight style), context may omit closeWhenFocusLost / knightCollectionUrl and include only isOpen.
Class: Core_Details
Key behaviors:
- Asset registration: Registers
editorScript,editorStyle,style(style-index.css), andviewScriptModulefromblock.json. Enqueues thestylehandle together with the global inlineprc-core-details-iconsrules onenqueue_block_assets, and in the editor viaenqueue_block_editor_assets, so caret dark-mode rules load wherever the collapsible UI appears. - Interactivity directives: When
closeWhenFocusLostis true, the Knight style is active, or the block contains an entity iframe, injectsdata-wp-interactive="core/details"anddata-wp-context(merged keys:closeWhenFocusLostandknightCollectionUrlwhen applicable;isOpenwhen an entity iframe is present). When focus-lost is enabled, addsdata-wp-on-document--click="actions.handleOutsideClick". When an entity iframe is present, addsdata-wp-on--toggle,data-wp-watch--sync-entity-iframes, anddata-wp-on--pointerenteron<summary>as described above. - Knight logo click: When the Knight style is active, injects
data-wp-on--click="actions.handleSummaryClick"on<summary>(can coexist with entity iframe prefetch on the same<summary>). - View script enqueuing: Enqueues the view script module when focus-lost, Knight style, or entity iframe integration is needed
- Errant tag cleanup:
filter_details_outputremoves empty<a>tags (from Word doc copy-paste) - Print engine: Registers a print callback that forces
<details open>on/printroutes so closed accordion panels render expanded content for PDF capture
<details
class="wp-block-details is-style-plus-icon has-ui-beige-very-light-background-color has-background"
data-wp-interactive="core/details"
data-wp-context='{"closeWhenFocusLost":true}'
data-wp-on-document--click="actions.handleOutsideClick"
>
<summary>About this research</summary>
<p>Methodology content here...</p>
</details>| Variation Name | Title | Description |
|---|---|---|
collapsible |
Collapsible | Pre-styled with plus-icon style, beige background, "About this research" summary, border, and sans-serif font |
pew-knight-co-branded |
Pew Knight Co-Branded | Knight Initiative branding with logo, top/bottom borders only, pre-populated with a link paragraph and placeholder |
Transforms from the legacy prc-block/collapsible block:
- Priority 1: Non-co-branded collapsibles transform to
core/detailswithis-style-plus-icon - Priority 2: Co-branded collapsibles transform to
core/detailswithis-style-pew-knight-co-branded