Allow templates to change list block placeholder by adding it as an attribute #13013
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.
Description
Heading blocks and paragraph blocks allows templates (for CPT/InnerBlocks) to set a custom placeholder via attributes - like so:
const TEMPLATE =[ ['core/heading', { placeholder: 'Enter recipe title...' }] ]
This is not possible with the list block, as its placeholder is only defined on the
<RichText />
-component.Types of changes
This PR updates the list block to insert placeholders the same way the paragraph and heading blocks do. They do this by adding the placeholder as an empty attribute - so the standard placeholder defined on the RichText-component is used when it's not defined.
Screenshots
List block with default placeholder
List block as part of a custom block that uses an
<InnerBlocks />
component with a template that sets the list block's placeholder to be Enter steps...I tried to search the GitHub repo to see if there has been any discussion around what blocks can set placeholder text in a template and which can't - but I didn't find anything.
It seems like it's possible to set the placeholder attributes for:
But not for (I didn't check all blocks, but are willing to):
Is this a conscious decision/is there a reason for this?
Allowing templates to have custom placeholders really increase their usefulness (in my humble opinion).
How has this been tested?
Tested defining the placeholder attribute for a list block as part of a template for and a custom post type.
Tested on a local install with WordPress 5.0.1
Checklist:
(I'm quite new at this is, so if you have to tell I've done something wrong/it's terrible/it can't be used there will be no hard feelings.)