Gutenberg: Using wp.blocks.registerBlockStyle() adds `is-style-undefined`

Created on 25 Sep 2018  路  2Comments  路  Source: WordPress/gutenberg

Describe the bug
I am tying to add a tip style to the paragraph block by using wp.blocks.registerBlockStyle( 'core/paragraph', 'tip' ), but within both the editor and the front end, the class added ends up being is-style-undefined. I have also tried the example provided in the documentation for the quote, but am seeing the same issue.

Paragraph with tip style, but <code>is-style-undefined</code> class

I know the script I've added is firing because I see I have the option to add a style:
Tip style paragraph option

but it isn't consistent with blocks that have the styles object at time of registration (e.g. core/button):
Button styles

To Reproduce

  1. Add wp.blocks.registerBlockStyle( 'core/paragraph', 'tip' ); to a theme or plugin.
  2. Add a new paragraph to a post or page.
  3. Try changing the style to tip.
  4. Use the devtools to see that is-style-undefined is applied to the block.

Expected behavior
Adding a tip style should add the is-style-tip class to the paragraph block when it is selected.

Screenshots
See above.

Additional context

  • Gutenberg 3.9

Most helpful comment

@carrieforde the documentation for wp.blocks.registerBlockStyle needs updating. A plain string doesn't work for the second argument. Try the following instead and you should get the is-style-tip style:

wp.blocks.registerBlockStyle( 'core/paragraph', {
    name: 'tip',
    label: 'Tip'
} );

I've got a PR open to update that documentation page: https://github.com/WordPress/gutenberg/pull/10163

All 2 comments

@carrieforde the documentation for wp.blocks.registerBlockStyle needs updating. A plain string doesn't work for the second argument. Try the following instead and you should get the is-style-tip style:

wp.blocks.registerBlockStyle( 'core/paragraph', {
    name: 'tip',
    label: 'Tip'
} );

I've got a PR open to update that documentation page: https://github.com/WordPress/gutenberg/pull/10163

@joemaller Thanks so much. 馃挴 That most certainly did the trick.

Was this page helpful?
0 / 5 - 0 ratings