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

Consider allowing changing the default block style variation #11451

Closed
dgwyer opened this issue Nov 3, 2018 · 10 comments
Closed

Consider allowing changing the default block style variation #11451

dgwyer opened this issue Nov 3, 2018 · 10 comments
Labels
Customization Issues related to Phase 2: Customization efforts [Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement.
Milestone

Comments

@dgwyer
Copy link
Contributor

dgwyer commented Nov 3, 2018

Describe the bug
I'm trying to use registerBlockStyle() to register a custom block style variation for the core Button block and set it as the default style when a new Button block is inserted in the editor.

The result I'm currently getting is that the block style variation is available in block settings when the Button block is inserted, but it's not being set as the default.

To Reproduce
I'm adding the new block style variation via a Twenty Seventeen child theme using this code:
https://gist.github.com/dgwyer/fad8d4e5edfcd91cafc44b6a2b4a79d4

When the theme is active go to a page and add a Button block. The block style variation is available for selection but is not set as the default style.

Expected behavior
When the Button block is inserted into the editor the custom block style variation should be automatically set in block settings and in the inspector panel. Also the CSS class name should be automatically added to the Additional CSS Class text box in the inspector panel.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome v70

Additional context
I'm seeing the same behavior in Gutenberg v4.1.1 and v4.2.

@ocean90 ocean90 added [Feature] Block API API that allows to express the block paradigm. Customization Issues related to Phase 2: Customization efforts labels Nov 3, 2018
@youknowriad
Copy link
Contributor

That's probably because the block has already a default style variation. Why not just style the default variation in your stylesheet instead of adding a new one?

@youknowriad youknowriad added the [Status] Needs More Info Follow-up required in order to be actionable. label Nov 3, 2018
@dgwyer
Copy link
Contributor Author

dgwyer commented Nov 3, 2018

I'm testing out this feature as I'm currently writing a tutorial on block style variations.

According to the docs you can set the isDefault property to true to register the style variation to be active by default when a block is inserted.

This isn't currently happening as described by the docs. The isDefault attribute is effectively being ignored, hence the bug report.

Ideally you should be able to (re)set the default block style variation with the isDefault property even if one already exists in the block definition inside registerBlockType().

@youknowriad youknowriad removed the [Status] Needs More Info Follow-up required in order to be actionable. label Nov 3, 2018
@youknowriad youknowriad changed the title Setting default block style variation not working in registerBlockStyle() Consider allowing changing the default block style variation Nov 3, 2018
@youknowriad youknowriad added the [Type] Enhancement A suggestion for improvement. label Nov 3, 2018
@mtias mtias added this to the Future: Phase 2 milestone Nov 12, 2018
@Novalis80
Copy link

Novalis80 commented Nov 15, 2018

From the docs:

By adding isDefault: true, you can make registered style variation to be active by default when a block is inserted.

I am completely confused now. What is wrong, the implementation or the docs?

@samikeijonen
Copy link
Contributor

samikeijonen commented Dec 31, 2018

I confirm that isDefault: true just doesn't do anything.

It also seems that we can't change the default block variation to square either. It doesn't make sense to change default CSS to square since the Style label is still Rounded. Well, that's what I'm doing at the moment but is there a way to fix this?

@gziolo
Copy link
Member

gziolo commented Jan 29, 2019

With #11478 we clarified how isDefault works as of today:

By adding isDefault: true you can mark the registered style variation as the one that is recognized as active when no custom class name is provided. It also means that there will be no custom class name added to the HTML output for the style that is marked as default.

What else should be done to consider this issue resolved?

@Novalis80
Copy link

Novalis80 commented Jan 29, 2019

What else should be done to consider this issue resolved?

Hmm... confirm that it works according to the docs?

@samikeijonen
Copy link
Contributor

I can test later on. But I still worry that Style label is still Rounded (current default from Core) even if I change the default via isDefault: true.

  1. Set isDefault: true to button square style variant.
  2. Add a new button.
  3. Style label Rounded is still hightlighted, should be Square.

I'm going to test is that the case or not.

@youknowriad
Copy link
Contributor

@samikeijonen That's not what isDefault is about. The docs have been updated to clarify its purpose.

@samikeijonen
Copy link
Contributor

@youknowriad So basically it's another issue which I should open a new ticket?

@gziolo
Copy link
Member

gziolo commented Jan 29, 2019

Yes, that would be the best approach to open a new issue which proposes changes you expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Customization Issues related to Phase 2: Customization efforts [Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

7 participants