-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the nested block behavior in list block v2 (#39487)
* Implement the nested block behavior in list block v2 * Remove nested list wrapper div * add fixture Co-authored-by: Ella van Durpe <ella@vandurpe.com> Co-authored-by: ntsekouras <ntsekouras@outlook.com>
- Loading branch information
1 parent
6260c8a
commit 00a7f89
Showing
12 changed files
with
151 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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,26 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "core/list-item", | ||
"title": "List item", | ||
"category": "text", | ||
"parent": [ "core/list" ], | ||
"description": "Create a list item.", | ||
"textdomain": "default", | ||
"attributes": { | ||
"placeholder": { | ||
"type": "string" | ||
}, | ||
"content": { | ||
"type": "string", | ||
"source": "html", | ||
"selector": "li", | ||
"default": "", | ||
"__experimentalRole": "content" | ||
} | ||
}, | ||
"supports": { | ||
"className": false, | ||
"__experimentalSelector": "li" | ||
} | ||
} |
This file contains 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,32 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
RichText, | ||
useBlockProps, | ||
useInnerBlocksProps, | ||
} from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
export default function ListItemEdit( { attributes, setAttributes } ) { | ||
const blockProps = useBlockProps(); | ||
const innerBlocksProps = useInnerBlocksProps( blockProps, { | ||
allowedBlocks: [ 'core/list' ], | ||
} ); | ||
|
||
return ( | ||
<li { ...innerBlocksProps }> | ||
<RichText | ||
identifier="content" | ||
tagName="div" | ||
onChange={ ( nextContent ) => | ||
setAttributes( { content: nextContent } ) | ||
} | ||
value={ attributes.content } | ||
aria-label={ __( 'List text' ) } | ||
placeholder={ attributes.placeholder || __( 'List' ) } | ||
/> | ||
{ innerBlocksProps.children } | ||
</li> | ||
); | ||
} |
This file contains 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,21 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { list as icon } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
import edit from './edit'; | ||
import save from './save'; | ||
|
||
const { name } = metadata; | ||
|
||
export { metadata, name }; | ||
|
||
export const settings = { | ||
icon, | ||
edit, | ||
save, | ||
}; |
This file contains 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,13 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { InnerBlocks, RichText, useBlockProps } from '@wordpress/block-editor'; | ||
|
||
export default function save( { attributes } ) { | ||
return ( | ||
<li { ...useBlockProps.save() }> | ||
<RichText.Content value={ attributes.content } /> | ||
<InnerBlocks.Content /> | ||
</li> | ||
); | ||
} |
This file contains 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 |
---|---|---|
@@ -1,5 +1,18 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor'; | ||
|
||
const TEMPLATE = [ [ 'core/list-item' ] ]; | ||
|
||
function Edit() { | ||
return <div>List block v2</div>; | ||
const blockProps = useBlockProps(); | ||
const innerBlocksProps = useInnerBlocksProps( blockProps, { | ||
allowedBlocks: [ 'core/list-item' ], | ||
template: TEMPLATE, | ||
} ); | ||
|
||
return <ul { ...innerBlocksProps } />; | ||
} | ||
|
||
export default Edit; |
This file contains 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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
function Save() { | ||
return <div>List block v2</div>; | ||
} | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor'; | ||
|
||
export default Save; | ||
export default function save() { | ||
return ( | ||
<ul { ...useBlockProps.save() }> | ||
<InnerBlocks.Content /> | ||
</ul> | ||
); | ||
} |
This file contains 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 @@ | ||
<!-- wp:list-item --><li></li><!-- /wp:list-item --> |
This file contains 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,10 @@ | ||
[ | ||
{ | ||
"name": "core/list-item", | ||
"isValid": true, | ||
"attributes": { | ||
"content": "" | ||
}, | ||
"innerBlocks": [] | ||
} | ||
] |
This file contains 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,9 @@ | ||
[ | ||
{ | ||
"blockName": "core/list-item", | ||
"attrs": {}, | ||
"innerBlocks": [], | ||
"innerHTML": "<li></li>", | ||
"innerContent": [ "<li></li>" ] | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
test/integration/fixtures/blocks/core__list-item.serialized.html
This file contains 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 @@ | ||
<!-- wp:list-item --> | ||
<li></li> | ||
<!-- /wp:list-item --> |