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

List block: add color controls #21387

Merged
merged 2 commits into from Aug 27, 2020
Merged

Conversation

ZebulanStanphill
Copy link
Member

@ZebulanStanphill ZebulanStanphill commented Apr 3, 2020

Description

Adds color controls to the List block. If the Paragraph and Headings blocks are going to have color controls, then so should this one. Closes #9016.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@ZebulanStanphill ZebulanStanphill added [Type] Enhancement A suggestion for improvement. Needs Design Feedback Needs general design feedback. [Block] List Affects the List Block labels Apr 3, 2020
@github-actions
Copy link

github-actions bot commented Apr 3, 2020

Size Change: +57 B (0%)

Total Size: 1.16 MB

Filename Size Change
build/block-library/editor-rtl.css 7.61 kB +14 B (0%)
build/block-library/editor.css 7.61 kB +14 B (0%)
build/block-library/index.js 132 kB +14 B (0%)
build/block-library/style-rtl.css 7.77 kB +7 B (0%)
build/block-library/style.css 7.78 kB +8 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.67 kB 0 B
build/api-fetch/index.js 3.44 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 7.93 kB 0 B
build/block-directory/style-rtl.css 953 B 0 B
build/block-directory/style.css 952 B 0 B
build/block-editor/index.js 125 kB 0 B
build/block-editor/style-rtl.css 10.8 kB 0 B
build/block-editor/style.css 10.8 kB 0 B
build/block-library/theme-rtl.css 728 B 0 B
build/block-library/theme.css 729 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 48.3 kB 0 B
build/components/index.js 200 kB 0 B
build/components/style-rtl.css 15.7 kB 0 B
build/components/style.css 15.7 kB 0 B
build/compose/index.js 9.68 kB 0 B
build/core-data/index.js 11.8 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.45 kB 0 B
build/date/index.js 5.38 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.23 kB 0 B
build/edit-navigation/index.js 10.9 kB 0 B
build/edit-navigation/style-rtl.css 1.08 kB 0 B
build/edit-navigation/style.css 1.08 kB 0 B
build/edit-post/index.js 304 kB 0 B
build/edit-post/style-rtl.css 5.61 kB 0 B
build/edit-post/style.css 5.61 kB 0 B
build/edit-site/index.js 17 kB 0 B
build/edit-site/style-rtl.css 3.06 kB 0 B
build/edit-site/style.css 3.06 kB 0 B
build/edit-widgets/index.js 9.38 kB 0 B
build/edit-widgets/style-rtl.css 2.45 kB 0 B
build/edit-widgets/style.css 2.45 kB 0 B
build/editor/editor-styles-rtl.css 537 B 0 B
build/editor/editor-styles.css 539 B 0 B
build/editor/index.js 45.3 kB 0 B
build/editor/style-rtl.css 3.8 kB 0 B
build/editor/style.css 3.79 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.72 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keyboard-shortcuts/index.js 2.52 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.11 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.33 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.41 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 13.9 kB 0 B
build/server-side-render/index.js 2.71 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@ZebulanStanphill
Copy link
Member Author

I need some help with the styles. The Twenty Twenty styles override all of them.
image

@ZebulanStanphill
Copy link
Member Author

I rebased and revised this PR after the changes in #21428.

I tested in all the default WordPress themes. The good news is that the styles worked on the front-end in all of them. The bad news is that there were always issues in the editor:

In Twenty Twenty, background padding is not applied, and when a background color is set, the theme styles override some (but not all) of the text color options.

In Twenty Nineteen, only custom (non-palette) background/text colors work. Background padding is not applied.

In Twenty Seventeen, all styles except the background padding are applied properly.

Twenty Sixteen, Twenty Fifteen, Twenty Fourteen, Twenty Thirteen, Twenty Twelve, and Twenty Eleven all behave like Twenty Nineteen.

Twenty Ten was the worst of all. Only custom background colors were applied. Even custom text colors didn't work.

@ZebulanStanphill
Copy link
Member Author

For fun, I also tested the Classic theme (which appears to have no editor style support whatsoever). It behaved like Twenty Seventeen. It looks like the background padding style issue in the editor is caused by this style in the default editor stylesheet.

Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! Just one small comment below.

@@ -0,0 +1,4 @@
ol.has-background,
ul.has-background {
padding: $block-bg-padding--v $block-bg-padding--h;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This padding is being overridden by the default editor styles. You might want to make the selector .block-editor-block-list__block.has-background instead (that should also work for both types of lists)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block-editor-block-list__block is a class applied to all blocks in the editor, so I don't think I want to use that selector. (Also, that class is only applied in the editor.)

The default editor style rule (which gets loaded as .editor-styles-wrapper ol, .editor-styles-wrapper ul) has equal specificity as ol.has-background, ul.has-background. The only reason why the default editor styles take precedence is because they are loaded after the block styles. That sounds like a bug to me.

This comment was marked as duplicate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created #24011 to track this bug.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That issue is now fixed. I've created #30094 to remove the now-unnecessary editor styles.

@ZebulanStanphill ZebulanStanphill force-pushed the add/list-block-color-controls branch 2 times, most recently from d95284b to cfe8684 Compare April 21, 2020 15:24
Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@@ -0,0 +1,4 @@
ol.has-background,
ul.has-background {
padding: $block-bg-padding--v $block-bg-padding--h;

This comment was marked as duplicate.

@ZebulanStanphill
Copy link
Member Author

After switching to a doubled CSS class to account for the CSS override issue described here, background padding is correctly applied in Twenty Twenty and Twenty Nineteen.

In Twenty Seventeen, the selector to apply the background padding still isn't strong enough to take precedence. It's being overridden by a style rule targeting .edit-post-visual-editor ul:not(.wp-block-gallery).

(On a side note, the margin on List blocks seems to be broken in Twenty Seventeen in the editor, and it appears to have nothing to do with this PR. It looks like there's a regression caused by a change in master.)

@kjellr kjellr added the [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. label May 28, 2020
@ZebulanStanphill ZebulanStanphill changed the title List block: add color controls. List block: add color controls Jun 2, 2020
@youknowriad
Copy link
Contributor

Let's add gradients and ship this.
Also, let's consider adding font size and line-height (related #8171) in a follow-up PR.

@youknowriad
Copy link
Contributor

I'm still not sure yet about the solution for the specificity issues here but I'd like to find a way to communicate the changes properly to theme authors. Since the has-background is a new thing in the list block, we need to come up with a solution for theme authors and write dev note to explain how they should style their lists in order to retain the support.

I'd love eyes from @kjellr @jasmussen about the path forward here.

@ZebulanStanphill
Copy link
Member Author

Keep in mind that the styles always work on the front-end with all themes. It's only the editor styles that have specificity issues. I had hoped that something like #21102 would have been merged by now, but it looks like that is still not ready, and I doubt it will make it into WP 5.5.

@jasmussen
Copy link
Contributor

jasmussen commented Jun 24, 2020

Thanks for the PR, you've been making lots of great stuff, Zeb, thank you.

Before I comment on specificity issues, I wanted to circle back to this one:

If the Paragraph and Headings blocks are going to have color controls

One of the changes we have to make in the not too distant future, is to refactor both the list block and the quote block to hold nested blocks. The structure should ideally be List > Paragraph and Quote > Paragraph, because in HTML you could easily have an image (that isn't inline) in a list, or a nested quote inside a quote. We've known this for a while, but have held off because the select-parent situation hasn't been good enough. However, it's really getting there, and perhaps with some tweaks to the "parent absorbs child block toolbar" which @MichaelArestad has been thinking about, we can move forward. Not in time for 5.5, but maybe shortly after.

When that happens, and it does have to happen at some point, will the change in this PR become vestigial? Or will it change to be more like how color settings inside the Group block is?

@youknowriad
Copy link
Contributor

For me, the use of nested blocks don't have any impact on this PR as it applies those styles to the wrapper which exists in both cases.

@jasmussen
Copy link
Contributor

I had hoped that something like #21102 would have been merged by now, but it looks like that is still not ready, and I doubt it will make it into WP 5.5.

If and when that happens, it is likely going to happen in a way where if a plugin is detected which relies on there not being an iframe, we don't iframe the canvas. We can probably accept an amount of partial brokenness after a transition period.

I feel the same way about specificity here, that more important than anything, we feel the approach is the right approach, and then themes can update. It can get painful at moments, but in the end we are making these improvements with low specificity, including the iframe efforts, to benefit themers.

@kjellr
Copy link
Contributor

kjellr commented Jun 24, 2020

The bad news is that there were always issues in the editor...

I haven't tested, but from what I read above, it sounds like it's likely related to the issue that #22356 is trying to fix. In general, the color palettes aren't working in most of these themes right now.

I'm still not sure yet about the solution for the specificity issues here but I'd like to find a way to communicate the changes properly to theme authors. Since the has-background is a new thing in the list block, we need to come up with a solution for theme authors and write dev note to explain how they should style their lists in order to retain the support.

I'd love eyes from @kjellr @jasmussen about the path forward here.

In general, I think the approach here seems fine. I don't totally love the double selector specificity used in the editor, since it may be difficult or non-intuitive for theme authors to override that. Does it work without that in most other themes you've tested with? If so, it might be worth just patching Twenty Nineteen and Twenty Twenty if those are the problematic ones.

In terms of communication, we can include this in the Gutenberg + Themes roundup to start. That might help highlight it alongside the usual release notes.

@ZebulanStanphill
Copy link
Member Author

ZebulanStanphill commented Jun 24, 2020

Parent blocks should generally have color controls even if their children also have them (the Group block has background and text color controls), so whether the List block starts using nested blocks or not is irrelevant, I think.

In general, I think the approach here seems fine. I don't totally love the double selector specificity used in the editor, since it may be difficult or non-intuitive for theme authors to override that. Does it work without that in most other themes you've tested with? If so, it might be worth just patching Twenty Nineteen and Twenty Twenty if those are the problematic ones.

@kjellr The double selector for padding is needed to override core Gutenberg styles, not theme styles. The problem is that a certain default editor stylesheet is loaded after the default individual block editor styles, which I'm pretty sure is a bug.

@ZebulanStanphill ZebulanStanphill force-pushed the add/list-block-color-controls branch 2 times, most recently from 38fbc27 to aac320a Compare July 16, 2020 21:11
@ZebulanStanphill ZebulanStanphill removed the Needs Design Feedback Needs general design feedback. label Jul 16, 2020
@ZebulanStanphill
Copy link
Member Author

It looks like #22356 fixed the color palette issues. So this is mostly ready to merge. I just have one question:

Should I merge this with the workaround for the default editor styles being loaded later? Or should I merge it without that workaround and hope the issue gets properly fixed later on?

@jasmussen
Copy link
Contributor

Should I merge this with the workaround for the default editor styles being loaded later? Or should I merge it without that workaround and hope the issue gets properly fixed later on?

Good question that probably needs more than my opionion. And I'd personally prefer no workaround, but if workaround be sure to document it with a code comment and a note to remove it if a particular ticket gets addressed.

@ZebulanStanphill
Copy link
Member Author

Rebased and improved the inline comment note to link to the related issue on GitHub.

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.

This took way too long to review. Sorry for the delay

@ZebulanStanphill
Copy link
Member Author

@youknowriad Just to be clear, are you okay with this being merged with the workaround for #24011 included?

@youknowriad
Copy link
Contributor

yes, I'm personally fine with that. This is not the only place where such issue can happen and the value provided by this PR is important enough that we can live with the small workaround while we figure out a better way to load styles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] List Affects the List Block [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to change colour when choosing blog "list"
5 participants