-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Block Library: Add Description List block #81728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SteveRyan-ASU
wants to merge
6
commits into
WordPress:trunk
Choose a base branch
from
SteveRyan-ASU:try-description-list-wcus2026
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b5b6e0b
Block Library: Add Description List block
SteveRyan-ASU f5f300f
TSX remediation steps. Updated docs files.
SteveRyan-ASU 815c7d5
Fix Description List TypeScript integration
SteveRyan-ASU 81d5eb5
Correct file routing for Vitest tests.
SteveRyan-ASU 71ac8f7
Add end-to-end tests for Description List
SteveRyan-ASU ea61c59
Fix Description List keyboard transforms
SteveRyan-ASU File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Description Detail | ||
|
|
||
| <!-- START TOKEN(Autogenerated block API docs) --> | ||
| Add a description to a term. | ||
|
|
||
| - **Name:** `core/description-detail` | ||
| - **Category:** [text](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/) | ||
| - **API Version:** [3](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-api-versions/) | ||
| - **Block Type:** Unknown | ||
|
|
||
| ## Block Relationships | ||
|
|
||
| **[Parent](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#parent) blocks (direct):** | ||
| - [`core/description-list`](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-description-list/) | ||
|
|
||
| ## Attributes | ||
|
|
||
| _Defined via the [`attributes`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/) property in block.json._ | ||
|
|
||
| | Attribute | [Type](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#type-validation) | [Default](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#default-value) | Description | | ||
| |-----------|------|---------|-------------| | ||
| | `placeholder` | `string` | — | — | | ||
| | `content` | `rich-text` | — | [Source](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#value-source): `rich-text`. [Selector](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#value-source): `dd`. [Role](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#role): `content` | | ||
|
|
||
| ## Supports | ||
|
|
||
| _Defined via the [`supports`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/) property in block.json._ | ||
|
|
||
| - [`anchor`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#anchor): `true` | ||
| - [`html`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#html): `false` | ||
| - [`className`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#classname): `false` | ||
| - [`splitting`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#splitting): `true` | ||
| - [`color`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color): | ||
| - [`gradients`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color-gradients): `true` | ||
| - [`link`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color-link): `true` | ||
| - [`background`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color-background): `true` | ||
| - [`spacing`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#spacing): | ||
| - `margin`: `true` | ||
| - `padding`: `true` | ||
| - [`typography`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#typography): | ||
| - [`fontSize`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#typography-fontsize): `true` | ||
| - [`lineHeight`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#typography-lineheight): `true` | ||
| - [`interactivity`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#interactivity): | ||
| - `clientNavigation`: `true` | ||
|
|
||
| ## CSS Selectors | ||
|
|
||
| _Defined via the [`selectors`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-selectors/) property in block.json._ | ||
|
|
||
| - **root**: `.wp-block-description-list > dd` | ||
| - **border**: `.wp-block-description-list > dd` | ||
|
|
||
| ## Block Markup | ||
|
|
||
| This is a [**static block**](https://developer.wordpress.org/block-editor/getting-started/fundamentals/static-dynamic-rendering/). The markup is saved directly in the post content. | ||
|
|
||
| ```html | ||
| <!-- wp:description-detail --> | ||
| <dd>Description</dd> | ||
| <!-- /wp:description-detail --> | ||
| ``` | ||
|
|
||
| ## Source | ||
|
|
||
| - [block.json](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/description-detail/block.json) ([reference](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/)) | ||
| - [Source directory](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/description-detail/) — browse the `edit` and `save` source files, `index.php`, and more. | ||
|
|
||
| <!-- END TOKEN(Autogenerated block API docs) --> | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| { | ||
| "$schema": "https://schemas.wp.org/trunk/block.json", | ||
| "apiVersion": 3, | ||
| "name": "core/description-detail", | ||
| "title": "Description Detail", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should call it Definition Description? |
||
| "category": "text", | ||
| "parent": [ "core/description-list" ], | ||
| "description": "Add a description to a term.", | ||
| "textdomain": "default", | ||
| "attributes": { | ||
| "placeholder": { | ||
| "type": "string" | ||
| }, | ||
| "content": { | ||
| "type": "rich-text", | ||
| "source": "rich-text", | ||
| "selector": "dd", | ||
| "role": "content" | ||
| } | ||
| }, | ||
| "supports": { | ||
| "anchor": true, | ||
| "html": false, | ||
| "className": false, | ||
| "splitting": true, | ||
| "__experimentalBorder": { | ||
| "color": true, | ||
| "radius": true, | ||
| "style": true, | ||
| "width": true | ||
| }, | ||
| "color": { | ||
| "gradients": true, | ||
| "link": true, | ||
| "background": true, | ||
| "__experimentalDefaultControls": { | ||
| "text": true | ||
| } | ||
| }, | ||
| "spacing": { | ||
| "margin": true, | ||
| "padding": true, | ||
| "__experimentalDefaultControls": { | ||
| "margin": false, | ||
| "padding": false | ||
| } | ||
| }, | ||
| "typography": { | ||
| "fontSize": true, | ||
| "lineHeight": true, | ||
| "__experimentalFontFamily": true, | ||
| "__experimentalFontWeight": true, | ||
| "__experimentalFontStyle": true, | ||
| "__experimentalTextTransform": true, | ||
| "__experimentalTextDecoration": true, | ||
| "__experimentalLetterSpacing": true, | ||
| "__experimentalDefaultControls": { | ||
| "fontSize": true | ||
| } | ||
| }, | ||
| "interactivity": { | ||
| "clientNavigation": true | ||
| } | ||
| }, | ||
| "selectors": { | ||
| "root": ".wp-block-description-list > dd", | ||
| "border": ".wp-block-description-list > dd" | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { __ } from '@wordpress/i18n'; | ||
| // @ts-expect-error `@wordpress/block-editor` does not expose type declarations for its entry point. | ||
| import { RichText, useBlockProps } from '@wordpress/block-editor'; | ||
| import { useMergeRefs } from '@wordpress/compose'; | ||
| import type { BlockEditProps, Block } from '@wordpress/blocks'; | ||
| import type { RichTextData } from '@wordpress/rich-text'; | ||
| import useKeyboardTransform from '../description-term/use-keyboard-transform'; | ||
|
|
||
| type DescriptionListItemAttributes = { | ||
| content: string | RichTextData; | ||
| placeholder?: string; | ||
| }; | ||
|
|
||
| type DescriptionListItemEditProps = | ||
| BlockEditProps< DescriptionListItemAttributes > & { | ||
| mergeBlocks?: ( clientIdA: string, clientIdB: string ) => void; | ||
| onReplace?: ( | ||
| blocks: Block[], | ||
| indexToSelect?: number, | ||
| initialPosition?: number | ||
| ) => void; | ||
| onRemove?: () => void; | ||
| }; | ||
|
|
||
| export default function Edit( { | ||
| attributes, | ||
| setAttributes, | ||
| mergeBlocks, | ||
| onReplace, | ||
| onRemove, | ||
| clientId, | ||
| }: DescriptionListItemEditProps ) { | ||
| const { content, placeholder } = attributes; | ||
| const blockProps = useBlockProps(); | ||
| const keyboardTransformRef = useKeyboardTransform( { | ||
| attributes, | ||
| blockName: 'core/description-detail', | ||
| clientId, | ||
| } ); | ||
| const ref = useMergeRefs( [ blockProps.ref, keyboardTransformRef ] ); | ||
|
|
||
| return ( | ||
| <RichText | ||
| identifier="content" | ||
| tagName="dd" | ||
| { ...blockProps } | ||
| ref={ ref } | ||
| value={ content } | ||
| onChange={ ( newContent: string ) => | ||
| setAttributes( { content: newContent } ) | ||
| } | ||
| onMerge={ mergeBlocks } | ||
| onReplace={ onReplace } | ||
| onRemove={ onRemove } | ||
| placeholder={ placeholder || __( 'Description' ) } | ||
| /> | ||
| ); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { listItem as icon } from '@wordpress/icons'; | ||
| import initBlock from '../utils/init-block'; | ||
| import edit from './edit'; | ||
| import metadata from './block.json'; | ||
| import save from './save'; | ||
| import transforms from './transforms'; | ||
|
|
||
| const { name } = metadata; | ||
|
|
||
| export { metadata, name }; | ||
|
|
||
| export const settings = { | ||
| icon, | ||
| edit, | ||
| save, | ||
| merge( attributes, attributesToMerge ) { | ||
| return { | ||
| ...attributes, | ||
| content: attributes.content + attributesToMerge.content, | ||
| }; | ||
| }, | ||
| transforms, | ||
| __experimentalLabel( attributes, { context } ) { | ||
| const { content } = attributes; | ||
| const customName = attributes?.metadata?.name; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This all seems a little odd. Isn't this handled by the editor? Are other blocks doing this? |
||
| const hasContent = content?.trim().length > 0; | ||
|
|
||
| if ( context === 'list-view' && ( customName || hasContent ) ) { | ||
| return customName || content; | ||
| } | ||
|
|
||
| if ( context === 'breadcrumb' && customName ) { | ||
| return customName; | ||
| } | ||
| }, | ||
| }; | ||
|
|
||
| export const init = () => initBlock( { name, metadata, settings } ); | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { init } from './'; | ||
|
|
||
| export default init(); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // @ts-expect-error `@wordpress/block-editor` does not expose type declarations for its entry point. | ||
| import { RichText, useBlockProps } from '@wordpress/block-editor'; | ||
| import type { BlockSaveProps } from '@wordpress/blocks'; | ||
| import type { RichTextData } from '@wordpress/rich-text'; | ||
|
|
||
| type DescriptionListItemAttributes = { | ||
| content: string | RichTextData; | ||
| placeholder?: string; | ||
| }; | ||
|
|
||
| export default function save( { | ||
| attributes, | ||
| }: BlockSaveProps< DescriptionListItemAttributes > ) { | ||
| return ( | ||
| <dd { ...useBlockProps.save() }> | ||
| <RichText.Content value={ attributes.content } /> | ||
| </dd> | ||
| ); | ||
| } |
14 changes: 14 additions & 0 deletions
14
packages/block-library/src/description-detail/transforms.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { createBlock } from '@wordpress/blocks'; | ||
|
|
||
| const transforms = { | ||
| to: [ | ||
| { | ||
| type: 'block', | ||
| blocks: [ 'core/description-term' ], | ||
| transform: ( attributes ) => | ||
| createBlock( 'core/description-term', attributes ), | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| export default transforms; |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.