From c7b24dad4232df3f40f64c46fc0852f0c0618a78 Mon Sep 17 00:00:00 2001 From: Aki Hamano Date: Wed, 8 Jan 2025 22:36:28 +0900 Subject: [PATCH 1/4] Fix conflict --- docs/reference-guides/core-blocks.md | 2 +- packages/block-library/src/details/block.json | 4 ++++ packages/block-library/src/details/edit.js | 17 ++++++++++++++++- packages/block-library/src/details/save.js | 4 ++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index 3b251813e41c0a..0726d38cf75b51 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -255,7 +255,7 @@ Hide and show additional content. ([Source](https://github.com/WordPress/gutenbe - **Name:** core/details - **Category:** text - **Supports:** align (full, wide), anchor, color (background, gradients, link, text), interactivity (clientNavigation), layout (~~allowEditing~~), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~ -- **Attributes:** allowedBlocks, showContent, summary +- **Attributes:** allowedBlocks, name, showContent, summary ## Embed diff --git a/packages/block-library/src/details/block.json b/packages/block-library/src/details/block.json index e28d94c03b9aa0..31d13ed9832809 100644 --- a/packages/block-library/src/details/block.json +++ b/packages/block-library/src/details/block.json @@ -8,6 +8,10 @@ "keywords": [ "accordion", "summary", "toggle", "disclosure" ], "textdomain": "default", "attributes": { + "name": { + "type": "string", + "default": "" + }, "showContent": { "type": "boolean", "default": false diff --git a/packages/block-library/src/details/edit.js b/packages/block-library/src/details/edit.js index 9cf6a7a8456121..3f1c1e6f240a4a 100644 --- a/packages/block-library/src/details/edit.js +++ b/packages/block-library/src/details/edit.js @@ -10,6 +10,7 @@ import { } from '@wordpress/block-editor'; import { useSelect } from '@wordpress/data'; import { + TextControl, ToggleControl, __experimentalToolsPanel as ToolsPanel, __experimentalToolsPanelItem as ToolsPanelItem, @@ -31,7 +32,7 @@ const TEMPLATE = [ ]; function DetailsEdit( { attributes, setAttributes, clientId } ) { - const { showContent, summary, allowedBlocks } = attributes; + const { name, showContent, summary, allowedBlocks } = attributes; const blockProps = useBlockProps(); const innerBlocksProps = useInnerBlocksProps( blockProps, { template: TEMPLATE, @@ -89,6 +90,20 @@ function DetailsEdit( { attributes, setAttributes, clientId } ) { + + + setAttributes( { name: newName } ) + } + help={ __( + 'When using the name attribute to assign the same name to a group of detail elements, only one element in the set is opened at a time.' + ) } + /> +
+
From 38c2acdc27433c1cf6b742669f4cd78cceedb41b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Wrede?= Date: Tue, 12 Dec 2023 11:45:44 +0100 Subject: [PATCH 2/4] Don't save empty string. --- packages/block-library/src/details/save.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/details/save.js b/packages/block-library/src/details/save.js index e13c2ab2db02a9..076b7b766c5983 100644 --- a/packages/block-library/src/details/save.js +++ b/packages/block-library/src/details/save.js @@ -9,7 +9,7 @@ export default function save( { attributes } ) { const blockProps = useBlockProps.save(); return ( -
+
From 427f3791e7ec2b8e80945ac60b8334bd33f72447 Mon Sep 17 00:00:00 2001 From: Aki Hamano Date: Wed, 8 Jan 2025 22:41:19 +0900 Subject: [PATCH 3/4] Update help text --- packages/block-library/src/details/edit.js | 2 +- packages/block-library/src/details/save.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/details/edit.js b/packages/block-library/src/details/edit.js index 3f1c1e6f240a4a..c2c28ca6a0bfe2 100644 --- a/packages/block-library/src/details/edit.js +++ b/packages/block-library/src/details/edit.js @@ -100,7 +100,7 @@ function DetailsEdit( { attributes, setAttributes, clientId } ) { setAttributes( { name: newName } ) } help={ __( - 'When using the name attribute to assign the same name to a group of detail elements, only one element in the set is opened at a time.' + 'Enables multiple Details blocks with the same name attribute to be connected, with only one open at a time.' ) } /> diff --git a/packages/block-library/src/details/save.js b/packages/block-library/src/details/save.js index 076b7b766c5983..c7594d4d5aa3f4 100644 --- a/packages/block-library/src/details/save.js +++ b/packages/block-library/src/details/save.js @@ -9,7 +9,11 @@ export default function save( { attributes } ) { const blockProps = useBlockProps.save(); return ( -
+
From 0a4786dd0bfbc28e579e5b1fad93a3c182e720df Mon Sep 17 00:00:00 2001 From: Aki Hamano Date: Fri, 17 Jan 2025 15:56:56 +0900 Subject: [PATCH 4/4] Use selector field --- packages/block-library/src/details/block.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/details/block.json b/packages/block-library/src/details/block.json index 31d13ed9832809..e4fadc4a064f97 100644 --- a/packages/block-library/src/details/block.json +++ b/packages/block-library/src/details/block.json @@ -8,10 +8,6 @@ "keywords": [ "accordion", "summary", "toggle", "disclosure" ], "textdomain": "default", "attributes": { - "name": { - "type": "string", - "default": "" - }, "showContent": { "type": "boolean", "default": false @@ -21,6 +17,12 @@ "source": "rich-text", "selector": "summary" }, + "name": { + "type": "string", + "source": "attribute", + "attribute": "name", + "selector": ".wp-block-details" + }, "allowedBlocks": { "type": "array" }