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

Issue displaying the proper name of the block variation vs default block name in the List View & Settings Panel #60797

Closed
zachmihalko opened this issue Apr 16, 2024 · 2 comments
Labels
[Feature] Block Variations Block variations, including introducing new variations and variations as a feature [Type] Question Questions about the design or development of the editor.

Comments

@zachmihalko
Copy link

Description

I am confused about how the name of the block variation is being applied.

Below I have two screenshots showing focusing on the default block "Heading" and then a block variation "Bullet Heading".

Here is my code for registering the block variation

wp.blocks.registerBlockVariation('core/heading', {
    name: 'bullet-heading',
    title: 'Bullet Heading',
    description: 'This is the custom heading block.',
    isActive: () => true,
    isDefault: false,
    attributes : {
        providerNameSlug: 'bullet-heading',
        className: "is-style-bulleted",
    }
});

NOTE: that I am also applying a block style to the Block Variation. Not sure if that has any affect.

But the ideal output would be that the default "Heading" block stayed named "Heading" and only the custom block variation when added would display in the List View and Settings panel with "Bullet Heading"

I set the isActive: () => true, based on the issue linked below but I think this has to be the wrong use of isActive based on the behavior I am seeing. But this was the only thing that was able to override the default name "Heading". Without isActive: () => true, I was then only seeing the default name "Heading" and it wouldn't show the custom block Variation name in the List View & Settings panels.

#51486

Screenshot 2024-04-16 at 5 36 12 PM Screenshot 2024-04-16 at 5 36 05 PM

Step-by-step reproduction instructions

  1. Add the same block variation to your variations.js
  2. Then add both the default and custom block variation to a block editor page
  3. You should see that it always shows the custom block variation

Screenshots, screen recording, code snippet

wp.blocks.registerBlockStyle('core/heading', {
    name: 'bulleted',
    label: 'Bulleted',
});

wp.blocks.registerBlockVariation('core/heading', {
    name: 'bullet-heading',
    title: 'Bullet Heading',
    description: 'This is the custom heading block.',
    isActive: () => true,
    isDefault: false,
    attributes : {
        providerNameSlug: 'bullet-heading',
        className: "is-style-bulleted",
    }
});
Screenshot 2024-04-16 at 5 36 12 PM Screenshot 2024-04-16 at 5 36 05 PM

Environment info

WP Core 6.5.2
Custom WP Theme
Chrome Version 123.0.6312.123

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@zachmihalko zachmihalko added the [Type] Bug An existing feature does not function as intended label Apr 16, 2024
@talldan talldan added [Type] Question Questions about the design or development of the editor. [Feature] Block Variations Block variations, including introducing new variations and variations as a feature and removed [Type] Bug An existing feature does not function as intended labels Apr 17, 2024
@talldan
Copy link
Contributor

talldan commented Apr 17, 2024

Yes, the usage of isActive is incorrect. Setting it to true indicates that that variation is always active for any instance of the heading block. In your case you need to use the arguments provided to isActive to check if the instance of your block has the "is-style-bulleted" classname and only return true if so.

Here are the docs for isActive (I think these could be improved a bit, they don't read very clearly for me):
https://developer.wordpress.org/block-editor/reference-guides/block-api/block-variations/#using-isactive

BTW, this isn't a support forum, so it'd be great if any questions about APIs are made to the discussion board, stack exchange or the WordPress forums in future.

@talldan talldan closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2024
@talldan
Copy link
Contributor

talldan commented Apr 17, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block Variations Block variations, including introducing new variations and variations as a feature [Type] Question Questions about the design or development of the editor.
Projects
None yet
Development

No branches or pull requests

2 participants