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

Not possible to undo a block style #11613

Closed
swissspidy opened this issue Nov 8, 2018 · 4 comments · Fixed by #12519
Closed

Not possible to undo a block style #11613

swissspidy opened this issue Nov 8, 2018 · 4 comments · Fixed by #12519
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Feature] History History, undo, redo, revisions, autosave. [Feature] Theme Style Variations Related to style variations provided by block themes [Type] Enhancement A suggestion for improvement.
Milestone

Comments

@swissspidy
Copy link
Member

Is your feature request related to a problem? Please describe.

If a block only has a single block style, it's not possible to remove that block style after you've selected it. You always need to add some sort of "default" style as well.

For example, I added a new "Pretitle" style for paragraphs like so:

registerBlockStyle( 'core/paragraph', {
	name: 'pretitle',
	label: 'Pretitle',
} );

When I now write some text, everything works as usual. Once I choose the "Pretitle" stye, it will be styled a bit differently. But after that, there's no way for me to undo this selection.

I tried things like clicking on the selected style again in the hopes that this would remove the style again, but with no lock.

That means I need to register a default style that I can switch back to:

registerBlockStyle( 'core/paragraph', {
	name: 'default',
	label: 'Default',
} );

This second style would not be styled by me or anything because it should keep the default styles of the editor/theme.

Describe the solution you'd like

If I add a style variant to a block which hasn't had one before, a default style option could be added automatically in the background.

Alternatively there could be a "Reset style" button or something that would restore the default block style.

@youknowriad
Copy link
Contributor

Thanks for raising this and yes this is exactly what the "isDefault" flag is for. You basically register a custom style with isDefault: true to "name" the default style, it won't apply any className.

If I add a style variant to a block which hasn't had one before, a default style option could be added automatically in the background.

I agree this could be improved and I like this solution.

@youknowriad youknowriad added [Type] Enhancement A suggestion for improvement. [Feature] Extensibility The ability to extend blocks or the editing experience labels Nov 8, 2018
@ellatrix ellatrix added the [Feature] History History, undo, redo, revisions, autosave. label Nov 27, 2018
@swissspidy swissspidy added the [Feature] Theme Style Variations Related to style variations provided by block themes label Dec 2, 2018
@swissspidy
Copy link
Member Author

I agree this could be improved and I like this solution.

Added a PR in #12519.

@youknowriad youknowriad added this to the Future: 5.x milestone Dec 19, 2018
@annestk
Copy link

annestk commented Dec 19, 2018

Temporary workaround for anyone experiencing this issue: Removing is-style-something from the input field at Block Settings > Advanced > Additional CSS Class will reset the block style

@nickfmc
Copy link

nickfmc commented Jan 21, 2019

Also worth noting you can only use 1 class name when registering a style for the default to clear. if you use the below code you will get is-style-my-button

wp.blocks.registerBlockStyle("core/button", {
        name: "my-button",
        label: "myButton"
      }); 

However if you used the below code even though your classes would be applied as is-style-my-button and u-block , the next time you click on a style it would append another is-style-my-button to the classes. so you end up with ( is-style-my-button u-block is-style-my-button) Not sure if you should be able to register a style with multiple classes to me it seams to make sense for a lot of people.

wp.blocks.registerBlockStyle("core/button", {
        name: "my-button u-block",
        label: "myButton"
      }); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Feature] History History, undo, redo, revisions, autosave. [Feature] Theme Style Variations Related to style variations provided by block themes [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants