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

Add default block style if missing #12519

Merged
merged 2 commits into from
Jan 29, 2019
Merged

Conversation

swissspidy
Copy link
Member

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:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@swissspidy swissspidy added [Type] Enhancement A suggestion for improvement. [Feature] Theme Style Variations Related to style variations provided by block themes labels Dec 2, 2018
@swissspidy
Copy link
Member Author

@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' ) ) {
Copy link
Contributor

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?

Copy link
Member Author

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 :-)

Copy link
Contributor

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?

Copy link
Member Author

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 🤔

Copy link
Contributor

@youknowriad youknowriad left a 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.

@youknowriad
Copy link
Contributor

some tests (unit or e2e) would be good :)

@youknowriad youknowriad added this to the 4.8 milestone Dec 9, 2018
@swissspidy
Copy link
Member Author

Cool. I'll try to add some tests. Is https://wordpress.org/gutenberg/handbook/contributors/testing-overview/ still the best reference for that?

@youknowriad
Copy link
Contributor

yes, the tests docs seems good. Let me know if you need help figuring it out.

@gziolo
Copy link
Member

gziolo commented Dec 14, 2018

@swissspidy you can ping me if you need any help with tests :)

@youknowriad youknowriad modified the milestones: 4.8, 4.9 Dec 19, 2018
@youknowriad youknowriad merged commit d1c78bf into master Jan 29, 2019
@youknowriad
Copy link
Contributor

Let's follow up with tests separately.

@youknowriad youknowriad deleted the add/dynamic-default-styles branch January 29, 2019 07:38
youknowriad pushed a commit that referenced this pull request Mar 6, 2019
* Add default block style if missing

* Add 'block style' context
youknowriad pushed a commit that referenced this pull request Mar 6, 2019
* Add default block style if missing

* Add 'block style' context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Theme Style Variations Related to style variations provided by block themes [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not possible to undo a block style
4 participants