Skip to content
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

Footnotes: show in inserter and placeholder #52445

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ Add a link to a downloadable file. ([Source](https://github.com/WordPress/gutenb

- **Name:** core/footnotes
- **Category:** text
- **Supports:** ~~html~~, ~~inserter~~, ~~multiple~~, ~~reusable~~
- **Supports:** ~~html~~, ~~multiple~~, ~~reusable~~
- **Attributes:**

## Classic
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/footnotes/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"supports": {
"html": false,
"multiple": false,
"inserter": false,
"reusable": false
},
"style": "wp-block-footnotes"
Expand Down
14 changes: 13 additions & 1 deletion packages/block-library/src/footnotes/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
import { RichText, useBlockProps } from '@wordpress/block-editor';
import { useEntityProp } from '@wordpress/core-data';
import { __ } from '@wordpress/i18n';
import { Placeholder } from '@wordpress/components';

export default function FootnotesEdit( { context: { postType, postId } } ) {
const [ meta, updateMeta ] = useEntityProp(
Expand All @@ -12,8 +14,18 @@ export default function FootnotesEdit( { context: { postType, postId } } ) {
postId
);
const footnotes = meta?.footnotes ? JSON.parse( meta.footnotes ) : [];
const blockProps = useBlockProps();

if ( ! footnotes.length ) {
return (
<Placeholder { ...blockProps }>
{ __( 'No footnotes yet.' ) }
</Placeholder>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Placeholder component might need to be wrapped in a div element, otherwise the component's margin styles overrides a theme's layout styles, causing the placeholder to be rendered flush against other blocks. For example, here the placeholder state is right next to the adjacent paragraph block:

image

As an example, the Table of Contents block has a wrapper div for its placeholder state, so it has a little more breathing room:

image

);
}

return (
<ol { ...useBlockProps() }>
<ol { ...blockProps }>
{ footnotes.map( ( { id, content } ) => (
<li key={ id }>
<RichText
Expand Down
Loading