-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add default block style if missing #12519
Conversation
@youknowriad Would love to get your thoughts on this |
onSwitch = noop, | ||
onHoverClassName = noop, | ||
} ) { | ||
if ( ! styles || styles.length === 0 ) { | ||
return null; | ||
} | ||
|
||
if ( ! type.styles && ! find( styles, 'isDefault' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this ! type.styles
really necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition checks whether the block type originally contains styles, whereas styles
contains all styles (original styles + ones added through registerBlockStyle
).
The default style only needs to be added when the block type didn't already contain styles in the beginning.
So yeah, it's necessary :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default style only needs to be added when the block type didn't already contain styles in the beginning.
I'm not certain I understand why? Why can't we always add a default style anytime we're missing one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Yeah I guess I did some wrong thinking there 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable to me. I'm temptatively adding it to 4.8.
some tests (unit or e2e) would be good :) |
Cool. I'll try to add some tests. Is https://wordpress.org/gutenberg/handbook/contributors/testing-overview/ still the best reference for that? |
yes, the tests docs seems good. Let me know if you need help figuring it out. |
@swissspidy you can ping me if you need any help with tests :) |
Let's follow up with tests separately. |
* Add default block style if missing * Add 'block style' context
* Add default block style if missing * Add 'block style' context
Description
This attempts to fix #11613 by adding a default block style if block styles were added to a block which doesn't have any by default.
How has this been tested?
Only manual testing so far. I could need some assistance if E2E tests or similar are needed.
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: