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

Allow templates to change list block placeholder by adding it as an attribute #13013

Closed
wants to merge 1 commit into from
Closed

Allow templates to change list block placeholder by adding it as an attribute #13013

wants to merge 1 commit into from

Conversation

annestk
Copy link

@annestk annestk commented Dec 19, 2018

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
image
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...
image

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:

  • Heading block
  • Paragraph block

But not for (I didn't check all blocks, but are willing to):

  • List block
  • Button block
  • Code block
  • Quote (neither quote field or citation field)
  • Pullquote (same)

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:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

(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.)

Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

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

Hi @annestk thank you for your contribution 👍

I agree we should be able to change placeholder of other blocks besides the paragraph.
But I'm not sure if adding attributes that are not used to generate the markup and are just used as part of the edit function is the correct approach.
There are many situations where we may want to customize the block besides the placeholder (disable some alignments, change the block description for users with vision problems and using screen readers etc...), we should work on an API that addresses all these cases.
We have an open issue #7931 to track this. As soon as we have this general mechanism we should be able to change the placeholder of other blocks.

@gziolo gziolo added [Feature] Block API API that allows to express the block paradigm. [Block] List Affects the List Block Needs Decision Needs a decision to be actionable or relevant labels Feb 7, 2019
@gziolo gziolo requested review from youknowriad and aduth February 7, 2019 13:07
@jorgefilipecosta
Copy link
Member

I'm closing this PR as we can track this problem in issue #7931.
Thank you @annestk for the effort in submitting this PR, I added a comment in #7931 describing this need, and the description/conceptualization of the use case was beneficial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] List Affects the List Block [Feature] Block API API that allows to express the block paradigm. Needs Decision Needs a decision to be actionable or relevant
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants