Skip to content

Instantly share code, notes, and snippets.

@mattwatsoncodes
Last active July 4, 2023 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattwatsoncodes/28c9b86db3e8d3134420332651f44ca2 to your computer and use it in GitHub Desktop.
Save mattwatsoncodes/28c9b86db3e8d3134420332651f44ca2 to your computer and use it in GitHub Desktop.
Force Block Style to use Default
// TODO: We should make a little function that handles this by reading the defaults from the block.json.
let blockProps = useBlockProps( {
className: 'my-block-name',
} );
let style = blockProps['className'].split( ' ' ).filter( className => className.startsWith( 'is-style-' ) )[0] || '';
// The default style does not automatically apply. Fix that.
if ( ! style ) {
style = 'is-style-default';
blockProps['className'] += ' ' + style;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment