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

blocks.getBlockDefaultClassName filter is not applied to heading, paragraph and image blocks. #16884

Closed
hatsumatsu opened this issue Aug 2, 2019 · 4 comments

Comments

@hatsumatsu
Copy link

Describe the bug
The filter blocks.getBlockDefaultClassName does not alter the class attribute of heading, paragraph and image block.

To reproduce
Steps to reproduce the behavior:

  1. Add the filter as decribed in the docs
function addBlockCustomClassName( className ) {
    return 'wp-block ' + className;
}

// Adding the filter
wp.hooks.addFilter(
    'blocks.getBlockDefaultClassName',
    'my-plugin/add-block-custom-class-name',
    addBlockCustomClassName
);
  1. Class attribute of blocks like columns, group etc. is altered correctly but paragraph, heading and image blocks are untouched.

Expected behavior
All block should be affected by the filter.

@youknowriad
Copy link
Contributor

That's not a bug, these blocks opt-out of the default className.

@hatsumatsu
Copy link
Author

@youknowriad okay, but why? In the editor these are treated as and called blocks. Shouldn't it be possible to target all blocks in CSS via a generic class?

Coming from #6639 it seems that both workarounds to easily target all blocks via one CSS selector don't work.

@youknowriad
Copy link
Contributor

okay, but why? In the editor these are treated as and called blocks

Because they are blocks, a block is not necessary something with a given class. A block can even be multiple DOM elements without any wrapper. A block doesn't map to a DOM element, it's just an entity that wrappes a fragment of content and allows you to edit it visually.

In the case of paragraphs, headings and images we decided to opt-out of these classNames because these blocks are too common and we don't want to pollute the post-content with these.

I hope that answers your questions.

@hatsumatsu
Copy link
Author

Okay, thanks for clarifying. Guess the expectations of what the desired markup looks like differ based on different frontend workflows. I was just hoping for a clean BEM-like code style...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants