JavaScript for WordPress Forums Gutenberg Development Add class to container div? Reply To: Add class to container div?

#103759
mikemcalister
Participant

Howdy folks,

I’m also working on something that uses filters to adjust classes, but I’m using blocks.getBlockDefaultClassName. Any clues on the cleanest way to get attributes (attributes.bgType) from the block passed through to this function? I tried a few different ways but haven’t been able to tap into them yet since it runs outside of the block’s render where attributes are defined. Thanks in advance for any tips!

wp.hooks.addFilter(
	"blocks.getBlockDefaultClassName",
	"atomicblocks/ab-column-block-class-name",
	abCustomClassName
);

function abCustomClassName( className, name ) {
	if ( 'atomic-blocks/ab-columns' === name ) {
		return classnames(
			className,
			'ab-has-bg-' + attributes.bgType
		);
	}
	return className;
}