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

Refactor nav block paddings/margins to inherit global styles. #31878

Merged
merged 6 commits into from Jun 1, 2021

Conversation

jasmussen
Copy link
Contributor

@jasmussen jasmussen commented May 17, 2021

Description

Fixes #31784.

This PR refactors how margins and paddings are applied to menu items, to allow it to inherit those values from what is defined in global styles. That requires reducing the specificity a great deal, as global styles simply targets a block name and then the link element inside.

The steps to test this are best described in #31784, but please try adding this to your experimental-theme.json:

"core/navigation-link": {
	"elements" : {
		"link": {
			"spacing": {
				"padding" : {
					"top" : ".5em",
					"right": "1em",
					"bottom": ".5em",
					"left": "1em"
				}
			}
		}
	}
},

By changing those values, menu items including submenu items should have padding adjusted to fix. In these screenshots I set it to the following:

		"core/navigation-link": {
			"elements" : {
				"link": {
					"spacing": {
						"padding" : {
							"top" : "1.5em",
							"right": "2em",
							"bottom": "1.5em",
							"left": "2em"
						}
					}
				}
			}
		},

Screenshot 2021-05-17 at 11 07 56

Note that this change will cause a regression in the TT1 theme. Previously we increased specificity to override, but we can't do that and still inherit global styles. Which TT1 must be fixed separately. Specificaly, it adds padding to the wrong element:

Screenshot 2021-05-17 at 11 11 21

Screenshot 2021-05-17 at 11 11 29

Additionally, this change won't affect the Page List block. The Page List by having its own different CSS classes does not inherit any of the paddings that the global styles system outputs. Probably a separate issue, but nevertheless.

How has this been tested?

Updated May 31st.

I've refactored this again to fix some issues with display on the frontend. The ideal test matrix remains:

  • Navigation screen
  • Setup states of the navigation block, please test mobile and desktop breakpoints.
  • Test editor and frontend.
  • Test with and without burger menu
  • Test with and without background colors applied.
  • Test with empty menu items (insert page link then press escape)
  • Test vertical and horizontal.

Intended behavior with no values in theme.json:

  • Top level menu items have zero padding and higher margin to compensate, submenu items have default padding.
  • When a background is applied, top level menu items have some padding, and the same in submenus, and reduced margins in submenus.
  • By default, dropdown menus have a white background and black text.
  • On small breakpoints, nested submenus open downwards. On wider breakpoints top menus open down, nested submenus open down and right. If the navigation block is justified right, or space-between, then menus on wide breakpoints will open down and left.
  • The Page List block outputs all pages on the site. When it's output inside the navigation block, that helps keep things in sync. As noted, the Page List doesn't currently inherit global styles.

Intende behavior with spacing values defined in theme.json:

  • Top level, and sublevel menu items, regardless of whether you have a background color defined, should have the spacing that is defined in global styles.

Please test using "Empty Theme" from https://github.com/WordPress/theme-experiments. As noted some themes provide their own paddings for the nav menu, meaning they will override our efforts here. More details in this trac ticket.

Test content

Here is some testing content you can use:

<!-- wp:paragraph -->
<p><strong>Colors and styles.</strong></p>
<!-- /wp:paragraph -->

<!-- wp:navigation {"orientation":"horizontal","itemsJustification":"center"} -->
<!-- wp:navigation-link {"label":"Home","type":"page","id":11,"url":"http://localhost:8888/","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"About","type":"page","id":648,"url":"http://localhost:8888/?page_id=648","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Qualities","type":"page","id":658,"url":"http://localhost:8888/?page_id=658","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Properties","type":"page","id":657,"url":"http://localhost:8888/?page_id=657","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Services","type":"page","id":656,"url":"http://localhost:8888/?page_id=656","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Lawn-mowing","type":"page","id":663,"url":"http://localhost:8888/?page_id=663","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Roto-tilling","type":"page","id":662,"url":"http://localhost:8888/?page_id=662","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Gnome dioramas","type":"page","id":664,"url":"http://localhost:8888/?page_id=664","kind":"post-type"} /-->
<!-- /wp:navigation-link -->
<!-- /wp:navigation-link -->

<!-- wp:navigation-link {"label":"Contact","type":"page","id":15,"url":"http://localhost:8888/?page_id=15","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Journal","type":"page","id":13,"url":"http://localhost:8888/?page_id=13","kind":"post-type"} /-->
<!-- /wp:navigation -->

<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:navigation {"orientation":"horizontal","itemsJustification":"right"} -->
<!-- wp:navigation-link {"label":"Home","type":"page","id":11,"url":"http://localhost:8888/","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"About","type":"page","id":648,"url":"http://localhost:8888/?page_id=648","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Qualities","type":"page","id":658,"url":"http://localhost:8888/?page_id=658","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Properties","type":"page","id":657,"url":"http://localhost:8888/?page_id=657","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Services","type":"page","id":656,"url":"http://localhost:8888/?page_id=656","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Lawn-mowing","type":"page","id":663,"url":"http://localhost:8888/?page_id=663","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Roto-tilling","type":"page","id":662,"url":"http://localhost:8888/?page_id=662","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Gnome dioramas","type":"page","id":664,"url":"http://localhost:8888/?page_id=664","kind":"post-type"} /-->
<!-- /wp:navigation-link -->
<!-- /wp:navigation-link -->

<!-- wp:navigation-link {"label":"Contact","type":"page","id":15,"url":"http://localhost:8888/?page_id=15","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Journal","type":"page","id":13,"url":"http://localhost:8888/?page_id=13","kind":"post-type"} /-->
<!-- /wp:navigation -->

<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:navigation {"orientation":"horizontal","itemsJustification":"space-between"} -->
<!-- wp:navigation-link {"label":"Home","type":"page","id":11,"url":"http://localhost:8888/","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Contact","type":"page","id":15,"url":"http://localhost:8888/?page_id=15","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Journal","type":"page","id":13,"url":"http://localhost:8888/?page_id=13","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"About","type":"page","id":648,"url":"http://localhost:8888/?page_id=648","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Qualities","type":"page","id":658,"url":"http://localhost:8888/?page_id=658","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Properties","type":"page","id":657,"url":"http://localhost:8888/?page_id=657","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Services","type":"page","id":656,"url":"http://localhost:8888/?page_id=656","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Lawn-mowing","type":"page","id":663,"url":"http://localhost:8888/?page_id=663","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Roto-tilling","type":"page","id":662,"url":"http://localhost:8888/?page_id=662","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Gnome dioramas","type":"page","id":664,"url":"http://localhost:8888/?page_id=664","kind":"post-type"} /-->
<!-- /wp:navigation-link -->
<!-- /wp:navigation-link -->
<!-- /wp:navigation -->

<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:navigation {"orientation":"horizontal","backgroundColor":"light-blue","itemsJustification":"space-between"} -->
<!-- wp:navigation-link {"label":"Home","type":"page","id":11,"url":"http://localhost:8888/","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Contact","type":"page","id":15,"url":"http://localhost:8888/?page_id=15","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Journal","type":"page","id":13,"url":"http://localhost:8888/?page_id=13","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"About","type":"page","id":648,"url":"http://localhost:8888/?page_id=648","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Qualities","type":"page","id":658,"url":"http://localhost:8888/?page_id=658","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Properties","type":"page","id":657,"url":"http://localhost:8888/?page_id=657","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Services","type":"page","id":656,"url":"http://localhost:8888/?page_id=656","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Lawn-mowing","type":"page","id":663,"url":"http://localhost:8888/?page_id=663","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Roto-tilling","type":"page","id":662,"url":"http://localhost:8888/?page_id=662","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Gnome dioramas","type":"page","id":664,"url":"http://localhost:8888/?page_id=664","kind":"post-type"} /-->
<!-- /wp:navigation-link -->
<!-- /wp:navigation-link -->
<!-- /wp:navigation -->

<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:navigation {"orientation":"horizontal","backgroundColor":"blinding-red","itemsJustification":"space-between"} -->
<!-- wp:navigation-link {"label":"Home","type":"page","id":11,"url":"http://localhost:8888/","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Contact","type":"page","id":15,"url":"http://localhost:8888/?page_id=15","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"About","type":"page","id":648,"url":"http://localhost:8888/?page_id=648","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Qualities","type":"page","id":658,"url":"http://localhost:8888/?page_id=658","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Properties","type":"page","id":657,"url":"http://localhost:8888/?page_id=657","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Services","type":"page","id":656,"url":"http://localhost:8888/?page_id=656","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Lawn-mowing","type":"page","id":663,"url":"http://localhost:8888/?page_id=663","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Roto-tilling","type":"page","id":662,"url":"http://localhost:8888/?page_id=662","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Gnome dioramas","type":"page","id":664,"url":"http://localhost:8888/?page_id=664","kind":"post-type"} /-->
<!-- /wp:navigation-link -->
<!-- /wp:navigation-link -->

<!-- wp:navigation-link {"label":"Journal","type":"page","id":13,"url":"http://localhost:8888/?page_id=13","kind":"post-type"} /-->
<!-- /wp:navigation -->

<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:navigation {"orientation":"horizontal","textColor":"text-gray","backgroundColor":"actual-black","itemsJustification":"space-between"} -->
<!-- wp:navigation-link {"label":"Home","type":"page","id":11,"url":"http://localhost:8888/","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Contact","type":"page","id":15,"url":"http://localhost:8888/?page_id=15","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Journal","type":"page","id":13,"url":"http://localhost:8888/?page_id=13","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"About","type":"page","id":648,"url":"http://localhost:8888/?page_id=648","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Qualities","type":"page","id":658,"url":"http://localhost:8888/?page_id=658","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Properties","type":"page","id":657,"url":"http://localhost:8888/?page_id=657","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Services","type":"page","id":656,"url":"http://localhost:8888/?page_id=656","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Lawn-mowing","type":"page","id":663,"url":"http://localhost:8888/?page_id=663","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Roto-tilling","type":"page","id":662,"url":"http://localhost:8888/?page_id=662","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Gnome dioramas","type":"page","id":664,"url":"http://localhost:8888/?page_id=664","kind":"post-type"} /-->
<!-- /wp:navigation-link -->
<!-- /wp:navigation-link -->
<!-- /wp:navigation -->

<!-- wp:paragraph -->
<p><strong>Horizontal w. submenus, page list:</strong></p>
<!-- /wp:paragraph -->

<!-- wp:navigation {"orientation":"horizontal"} -->
<!-- wp:page-list /-->
<!-- /wp:navigation -->

<!-- wp:paragraph -->
<p><strong>Vertical w. submenus, page list:</strong></p>
<!-- /wp:paragraph -->

<!-- wp:navigation {"orientation":"vertical"} -->
<!-- wp:page-list /-->
<!-- /wp:navigation -->

<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:paragraph -->
<p><strong>Horizontal w. submenus, manual items list:</strong></p>
<!-- /wp:paragraph -->

<!-- wp:navigation {"orientation":"horizontal"} -->
<!-- wp:navigation-link {"label":"Home","type":"page","id":11,"url":"http://localhost:8888/","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"About","type":"page","id":648,"url":"http://localhost:8888/?page_id=648","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Qualities","type":"page","id":658,"url":"http://localhost:8888/?page_id=658","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Properties","type":"page","id":657,"url":"http://localhost:8888/?page_id=657","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Services","type":"page","id":656,"url":"http://localhost:8888/?page_id=656","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Lawn-mowing","type":"page","id":663,"url":"http://localhost:8888/?page_id=663","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Roto-tilling","type":"page","id":662,"url":"http://localhost:8888/?page_id=662","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Gnome dioramas","type":"page","id":664,"url":"http://localhost:8888/?page_id=664","kind":"post-type"} /-->
<!-- /wp:navigation-link -->
<!-- /wp:navigation-link -->

<!-- wp:navigation-link {"label":"Contact","type":"page","id":15,"url":"http://localhost:8888/?page_id=15","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Journal","type":"page","id":13,"url":"http://localhost:8888/?page_id=13","kind":"post-type"} /-->
<!-- /wp:navigation -->

<!-- wp:paragraph -->
<p><strong>Vertical w. submenus, manual items list:</strong></p>
<!-- /wp:paragraph -->

<!-- wp:navigation {"orientation":"vertical"} -->
<!-- wp:navigation-link {"label":"Home","type":"page","id":11,"url":"http://localhost:8888/","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"About","type":"page","id":648,"url":"http://localhost:8888/?page_id=648","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Qualities","type":"page","id":658,"url":"http://localhost:8888/?page_id=658","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Properties","type":"page","id":657,"url":"http://localhost:8888/?page_id=657","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Services","type":"page","id":656,"url":"http://localhost:8888/?page_id=656","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Lawn-mowing","type":"page","id":663,"url":"http://localhost:8888/?page_id=663","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Roto-tilling","type":"page","id":662,"url":"http://localhost:8888/?page_id=662","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Gnome dioramas","type":"page","id":664,"url":"http://localhost:8888/?page_id=664","kind":"post-type"} /-->
<!-- /wp:navigation-link -->
<!-- /wp:navigation-link -->

<!-- wp:navigation-link {"label":"Contact","type":"page","id":15,"url":"http://localhost:8888/?page_id=15","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Journal","type":"page","id":13,"url":"http://localhost:8888/?page_id=13","kind":"post-type"} /-->
<!-- /wp:navigation -->

<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:paragraph -->
<p><strong>Burger:</strong></p>
<!-- /wp:paragraph -->

<!-- wp:navigation {"orientation":"horizontal","itemsJustification":"right","isResponsive":true} -->
<!-- wp:navigation-link {"label":"Home","type":"page","id":11,"url":"http://localhost:8888/","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"About","type":"page","id":648,"url":"http://localhost:8888/?page_id=648","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Qualities","type":"page","id":658,"url":"http://localhost:8888/?page_id=658","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Properties","type":"page","id":657,"url":"http://localhost:8888/?page_id=657","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Services","type":"page","id":656,"url":"http://localhost:8888/?page_id=656","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Lawn-mowing","type":"page","id":663,"url":"http://localhost:8888/?page_id=663","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Roto-tilling","type":"page","id":662,"url":"http://localhost:8888/?page_id=662","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Gnome dioramas","type":"page","id":664,"url":"http://localhost:8888/?page_id=664","kind":"post-type"} /-->
<!-- /wp:navigation-link -->
<!-- /wp:navigation-link -->

<!-- wp:navigation-link {"label":"Contact","type":"page","id":15,"url":"http://localhost:8888/?page_id=15","kind":"post-type"} /-->

<!-- wp:navigation-link {"label":"Journal","type":"page","id":13,"url":"http://localhost:8888/?page_id=13","kind":"post-type"} /-->
<!-- /wp:navigation -->

Types of changes

Because of the need to be able to inherit properties generated by global styles, I had to remove quite a few classes and specificity. While the overall structure is the same, this on its own can cause headaches, notably for themes. All that being said, I think this PR is worth it. I will create separate tickets for page list and TT1 to fix there, but the reduction in specificity is almost always a good thing, and giving control of padding directly to the global style system feels worth it.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • 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 (please manually search all *.native.js files for terms that need renaming or removal).

@github-actions
Copy link

github-actions bot commented May 17, 2021

Size Change: -666 B (0%)

Total Size: 1.03 MB

Filename Size Change
build/block-library/blocks/navigation/editor-rtl.css 1.55 kB +9 B (+1%)
build/block-library/blocks/navigation/editor.css 1.55 kB +9 B (+1%)
build/block-library/blocks/navigation/style-rtl.css 1.63 kB -172 B (-10%) 👏
build/block-library/blocks/navigation/style.css 1.63 kB -170 B (-9%)
build/block-library/blocks/page-list/style-rtl.css 240 B +7 B (+3%)
build/block-library/blocks/page-list/style.css 240 B +7 B (+3%)
build/block-library/blocks/search/editor-rtl.css 211 B +22 B (+12%) ⚠️
build/block-library/blocks/search/editor.css 211 B +22 B (+12%) ⚠️
build/block-library/editor-rtl.css 9.94 kB +12 B (0%)
build/block-library/editor.css 9.94 kB +16 B (0%)
build/block-library/index.js 147 kB +7 B (0%)
build/block-library/style-rtl.css 10.1 kB -218 B (-2%)
build/block-library/style.css 10.1 kB -217 B (-2%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.12 kB 0 B
build/annotations/index.js 2.93 kB 0 B
build/api-fetch/index.js 2.42 kB 0 B
build/autop/index.js 2.28 kB 0 B
build/blob/index.js 672 B 0 B
build/block-directory/index.js 6.61 kB 0 B
build/block-directory/style-rtl.css 989 B 0 B
build/block-directory/style.css 990 B 0 B
build/block-editor/index.js 118 kB 0 B
build/block-editor/style-rtl.css 12.9 kB 0 B
build/block-editor/style.css 12.9 kB 0 B
build/block-library/blocks/archives/editor-rtl.css 61 B 0 B
build/block-library/blocks/archives/editor.css 60 B 0 B
build/block-library/blocks/archives/style-rtl.css 65 B 0 B
build/block-library/blocks/archives/style.css 65 B 0 B
build/block-library/blocks/audio/editor-rtl.css 58 B 0 B
build/block-library/blocks/audio/editor.css 58 B 0 B
build/block-library/blocks/audio/style-rtl.css 112 B 0 B
build/block-library/blocks/audio/style.css 112 B 0 B
build/block-library/blocks/block/editor-rtl.css 161 B 0 B
build/block-library/blocks/block/editor.css 161 B 0 B
build/block-library/blocks/button/editor-rtl.css 475 B 0 B
build/block-library/blocks/button/editor.css 474 B 0 B
build/block-library/blocks/button/style-rtl.css 603 B 0 B
build/block-library/blocks/button/style.css 602 B 0 B
build/block-library/blocks/buttons/editor-rtl.css 315 B 0 B
build/block-library/blocks/buttons/editor.css 315 B 0 B
build/block-library/blocks/buttons/style-rtl.css 375 B 0 B
build/block-library/blocks/buttons/style.css 375 B 0 B
build/block-library/blocks/calendar/style-rtl.css 208 B 0 B
build/block-library/blocks/calendar/style.css 208 B 0 B
build/block-library/blocks/categories/editor-rtl.css 84 B 0 B
build/block-library/blocks/categories/editor.css 83 B 0 B
build/block-library/blocks/categories/style-rtl.css 79 B 0 B
build/block-library/blocks/categories/style.css 79 B 0 B
build/block-library/blocks/code/style-rtl.css 90 B 0 B
build/block-library/blocks/code/style.css 90 B 0 B
build/block-library/blocks/columns/editor-rtl.css 190 B 0 B
build/block-library/blocks/columns/editor.css 190 B 0 B
build/block-library/blocks/columns/style-rtl.css 422 B 0 B
build/block-library/blocks/columns/style.css 422 B 0 B
build/block-library/blocks/cover/editor-rtl.css 644 B 0 B
build/block-library/blocks/cover/editor.css 646 B 0 B
build/block-library/blocks/cover/style-rtl.css 1.22 kB 0 B
build/block-library/blocks/cover/style.css 1.23 kB 0 B
build/block-library/blocks/embed/editor-rtl.css 486 B 0 B
build/block-library/blocks/embed/editor.css 486 B 0 B
build/block-library/blocks/embed/style-rtl.css 401 B 0 B
build/block-library/blocks/embed/style.css 400 B 0 B
build/block-library/blocks/file/editor-rtl.css 301 B 0 B
build/block-library/blocks/file/editor.css 300 B 0 B
build/block-library/blocks/file/frontend.js 773 B 0 B
build/block-library/blocks/file/style-rtl.css 255 B 0 B
build/block-library/blocks/file/style.css 255 B 0 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB 0 B
build/block-library/blocks/freeform/editor.css 2.44 kB 0 B
build/block-library/blocks/gallery/editor-rtl.css 704 B 0 B
build/block-library/blocks/gallery/editor.css 705 B 0 B
build/block-library/blocks/gallery/style-rtl.css 1.06 kB 0 B
build/block-library/blocks/gallery/style.css 1.06 kB 0 B
build/block-library/blocks/group/editor-rtl.css 160 B 0 B
build/block-library/blocks/group/editor.css 160 B 0 B
build/block-library/blocks/group/style-rtl.css 57 B 0 B
build/block-library/blocks/group/style.css 57 B 0 B
build/block-library/blocks/heading/editor-rtl.css 129 B 0 B
build/block-library/blocks/heading/editor.css 129 B 0 B
build/block-library/blocks/heading/style-rtl.css 76 B 0 B
build/block-library/blocks/heading/style.css 76 B 0 B
build/block-library/blocks/home-link/style-rtl.css 259 B 0 B
build/block-library/blocks/home-link/style.css 259 B 0 B
build/block-library/blocks/html/editor-rtl.css 281 B 0 B
build/block-library/blocks/html/editor.css 281 B 0 B
build/block-library/blocks/image/editor-rtl.css 717 B 0 B
build/block-library/blocks/image/editor.css 716 B 0 B
build/block-library/blocks/image/style-rtl.css 481 B 0 B
build/block-library/blocks/image/style.css 485 B 0 B
build/block-library/blocks/latest-comments/style-rtl.css 281 B 0 B
build/block-library/blocks/latest-comments/style.css 282 B 0 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B 0 B
build/block-library/blocks/latest-posts/editor.css 137 B 0 B
build/block-library/blocks/latest-posts/style-rtl.css 529 B 0 B
build/block-library/blocks/latest-posts/style.css 529 B 0 B
build/block-library/blocks/legacy-widget/editor-rtl.css 557 B 0 B
build/block-library/blocks/legacy-widget/editor.css 557 B 0 B
build/block-library/blocks/list/style-rtl.css 63 B 0 B
build/block-library/blocks/list/style.css 63 B 0 B
build/block-library/blocks/media-text/editor-rtl.css 176 B 0 B
build/block-library/blocks/media-text/editor.css 176 B 0 B
build/block-library/blocks/media-text/style-rtl.css 492 B 0 B
build/block-library/blocks/media-text/style.css 489 B 0 B
build/block-library/blocks/more/editor-rtl.css 434 B 0 B
build/block-library/blocks/more/editor.css 434 B 0 B
build/block-library/blocks/navigation-link/editor-rtl.css 633 B 0 B
build/block-library/blocks/navigation-link/editor.css 634 B 0 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B 0 B
build/block-library/blocks/navigation-link/style.css 94 B 0 B
build/block-library/blocks/navigation/frontend.js 2.86 kB 0 B
build/block-library/blocks/nextpage/editor-rtl.css 395 B 0 B
build/block-library/blocks/nextpage/editor.css 395 B 0 B
build/block-library/blocks/page-list/editor-rtl.css 310 B 0 B
build/block-library/blocks/page-list/editor.css 311 B 0 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B 0 B
build/block-library/blocks/paragraph/editor.css 157 B 0 B
build/block-library/blocks/paragraph/style-rtl.css 247 B 0 B
build/block-library/blocks/paragraph/style.css 248 B 0 B
build/block-library/blocks/post-author/editor-rtl.css 209 B 0 B
build/block-library/blocks/post-author/editor.css 209 B 0 B
build/block-library/blocks/post-author/style-rtl.css 183 B 0 B
build/block-library/blocks/post-author/style.css 184 B 0 B
build/block-library/blocks/post-comments-form/style-rtl.css 140 B 0 B
build/block-library/blocks/post-comments-form/style.css 140 B 0 B
build/block-library/blocks/post-comments/style-rtl.css 360 B 0 B
build/block-library/blocks/post-comments/style.css 359 B 0 B
build/block-library/blocks/post-content/editor-rtl.css 139 B 0 B
build/block-library/blocks/post-content/editor.css 139 B 0 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B 0 B
build/block-library/blocks/post-excerpt/editor.css 73 B 0 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B 0 B
build/block-library/blocks/post-excerpt/style.css 69 B 0 B
build/block-library/blocks/post-featured-image/editor-rtl.css 338 B 0 B
build/block-library/blocks/post-featured-image/editor.css 338 B 0 B
build/block-library/blocks/post-featured-image/style-rtl.css 141 B 0 B
build/block-library/blocks/post-featured-image/style.css 141 B 0 B
build/block-library/blocks/post-title/style-rtl.css 60 B 0 B
build/block-library/blocks/post-title/style.css 60 B 0 B
build/block-library/blocks/preformatted/style-rtl.css 103 B 0 B
build/block-library/blocks/preformatted/style.css 103 B 0 B
build/block-library/blocks/pullquote/editor-rtl.css 183 B 0 B
build/block-library/blocks/pullquote/editor.css 183 B 0 B
build/block-library/blocks/pullquote/style-rtl.css 318 B 0 B
build/block-library/blocks/pullquote/style.css 318 B 0 B
build/block-library/blocks/query-loop/editor-rtl.css 98 B 0 B
build/block-library/blocks/query-loop/editor.css 97 B 0 B
build/block-library/blocks/query-loop/style-rtl.css 315 B 0 B
build/block-library/blocks/query-loop/style.css 317 B 0 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B 0 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B 0 B
build/block-library/blocks/query-pagination/editor-rtl.css 270 B 0 B
build/block-library/blocks/query-pagination/editor.css 262 B 0 B
build/block-library/blocks/query-pagination/style-rtl.css 168 B 0 B
build/block-library/blocks/query-pagination/style.css 168 B 0 B
build/block-library/blocks/query-title/editor-rtl.css 86 B 0 B
build/block-library/blocks/query-title/editor.css 86 B 0 B
build/block-library/blocks/query/editor-rtl.css 131 B 0 B
build/block-library/blocks/query/editor.css 132 B 0 B
build/block-library/blocks/quote/style-rtl.css 169 B 0 B
build/block-library/blocks/quote/style.css 169 B 0 B
build/block-library/blocks/rss/editor-rtl.css 201 B 0 B
build/block-library/blocks/rss/editor.css 202 B 0 B
build/block-library/blocks/rss/style-rtl.css 290 B 0 B
build/block-library/blocks/rss/style.css 290 B 0 B
build/block-library/blocks/search/style-rtl.css 359 B 0 B
build/block-library/blocks/search/style.css 362 B 0 B
build/block-library/blocks/separator/editor-rtl.css 99 B 0 B
build/block-library/blocks/separator/editor.css 99 B 0 B
build/block-library/blocks/separator/style-rtl.css 251 B 0 B
build/block-library/blocks/separator/style.css 251 B 0 B
build/block-library/blocks/shortcode/editor-rtl.css 512 B 0 B
build/block-library/blocks/shortcode/editor.css 512 B 0 B
build/block-library/blocks/site-logo/editor-rtl.css 440 B 0 B
build/block-library/blocks/site-logo/editor.css 441 B 0 B
build/block-library/blocks/site-logo/style-rtl.css 154 B 0 B
build/block-library/blocks/site-logo/style.css 154 B 0 B
build/block-library/blocks/social-link/editor-rtl.css 164 B 0 B
build/block-library/blocks/social-link/editor.css 165 B 0 B
build/block-library/blocks/social-links/editor-rtl.css 800 B 0 B
build/block-library/blocks/social-links/editor.css 799 B 0 B
build/block-library/blocks/social-links/style-rtl.css 1.32 kB 0 B
build/block-library/blocks/social-links/style.css 1.33 kB 0 B
build/block-library/blocks/spacer/editor-rtl.css 308 B 0 B
build/block-library/blocks/spacer/editor.css 308 B 0 B
build/block-library/blocks/spacer/style-rtl.css 48 B 0 B
build/block-library/blocks/spacer/style.css 48 B 0 B
build/block-library/blocks/table/editor-rtl.css 478 B 0 B
build/block-library/blocks/table/editor.css 478 B 0 B
build/block-library/blocks/table/style-rtl.css 480 B 0 B
build/block-library/blocks/table/style.css 480 B 0 B
build/block-library/blocks/tag-cloud/editor-rtl.css 118 B 0 B
build/block-library/blocks/tag-cloud/editor.css 118 B 0 B
build/block-library/blocks/tag-cloud/style-rtl.css 94 B 0 B
build/block-library/blocks/tag-cloud/style.css 94 B 0 B
build/block-library/blocks/template-part/editor-rtl.css 551 B 0 B
build/block-library/blocks/template-part/editor.css 550 B 0 B
build/block-library/blocks/term-description/editor-rtl.css 90 B 0 B
build/block-library/blocks/term-description/editor.css 90 B 0 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B 0 B
build/block-library/blocks/text-columns/editor.css 95 B 0 B
build/block-library/blocks/text-columns/style-rtl.css 166 B 0 B
build/block-library/blocks/text-columns/style.css 166 B 0 B
build/block-library/blocks/verse/style-rtl.css 87 B 0 B
build/block-library/blocks/verse/style.css 87 B 0 B
build/block-library/blocks/video/editor-rtl.css 569 B 0 B
build/block-library/blocks/video/editor.css 570 B 0 B
build/block-library/blocks/video/style-rtl.css 173 B 0 B
build/block-library/blocks/video/style.css 173 B 0 B
build/block-library/common-rtl.css 1.26 kB 0 B
build/block-library/common.css 1.26 kB 0 B
build/block-library/reset-rtl.css 506 B 0 B
build/block-library/reset.css 507 B 0 B
build/block-library/theme-rtl.css 692 B 0 B
build/block-library/theme.css 693 B 0 B
build/block-serialization-default-parser/index.js 1.3 kB 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/blocks/index.js 47.2 kB 0 B
build/components/index.js 179 kB 0 B
build/components/style-rtl.css 16.2 kB 0 B
build/components/style.css 16.2 kB 0 B
build/compose/index.js 10 kB 0 B
build/core-data/index.js 12.1 kB 0 B
build/customize-widgets/index.js 9.85 kB 0 B
build/customize-widgets/style-rtl.css 1.45 kB 0 B
build/customize-widgets/style.css 1.44 kB 0 B
build/data-controls/index.js 828 B 0 B
build/data/index.js 7.22 kB 0 B
build/date/index.js 31.8 kB 0 B
build/deprecated/index.js 738 B 0 B
build/dom-ready/index.js 576 B 0 B
build/dom/index.js 4.62 kB 0 B
build/edit-navigation/index.js 13.9 kB 0 B
build/edit-navigation/style-rtl.css 3.08 kB 0 B
build/edit-navigation/style.css 3.08 kB 0 B
build/edit-post/classic-rtl.css 454 B 0 B
build/edit-post/classic.css 454 B 0 B
build/edit-post/index.js 58.4 kB 0 B
build/edit-post/style-rtl.css 6.87 kB 0 B
build/edit-post/style.css 6.86 kB 0 B
build/edit-site/index.js 25.9 kB 0 B
build/edit-site/style-rtl.css 4.75 kB 0 B
build/edit-site/style.css 4.75 kB 0 B
build/edit-widgets/index.js 15.7 kB 0 B
build/edit-widgets/style-rtl.css 3.42 kB 0 B
build/edit-widgets/style.css 3.42 kB 0 B
build/editor/index.js 38.2 kB 0 B
build/editor/style-rtl.css 3.92 kB 0 B
build/editor/style.css 3.91 kB 0 B
build/element/index.js 3.44 kB 0 B
build/escape-html/index.js 739 B 0 B
build/format-library/index.js 5.67 kB 0 B
build/format-library/style-rtl.css 637 B 0 B
build/format-library/style.css 639 B 0 B
build/hooks/index.js 1.76 kB 0 B
build/html-entities/index.js 628 B 0 B
build/i18n/index.js 3.73 kB 0 B
build/is-shallow-equal/index.js 709 B 0 B
build/keyboard-shortcuts/index.js 1.74 kB 0 B
build/keycodes/index.js 1.43 kB 0 B
build/list-reusable-blocks/index.js 2.07 kB 0 B
build/list-reusable-blocks/style-rtl.css 629 B 0 B
build/list-reusable-blocks/style.css 628 B 0 B
build/media-utils/index.js 3.08 kB 0 B
build/notices/index.js 1.07 kB 0 B
build/nux/index.js 2.31 kB 0 B
build/nux/style-rtl.css 718 B 0 B
build/nux/style.css 716 B 0 B
build/plugins/index.js 1.99 kB 0 B
build/primitives/index.js 1.03 kB 0 B
build/priority-queue/index.js 791 B 0 B
build/react-i18n/index.js 924 B 0 B
build/redux-routine/index.js 2.82 kB 0 B
build/reusable-blocks/index.js 2.53 kB 0 B
build/reusable-blocks/style-rtl.css 225 B 0 B
build/reusable-blocks/style.css 225 B 0 B
build/rich-text/index.js 10.6 kB 0 B
build/server-side-render/index.js 1.63 kB 0 B
build/shortcode/index.js 1.68 kB 0 B
build/token-list/index.js 847 B 0 B
build/url/index.js 1.95 kB 0 B
build/viewport/index.js 1.28 kB 0 B
build/warning/index.js 1.13 kB 0 B
build/widgets/index.js 1.67 kB 0 B
build/wordcount/index.js 1.24 kB 0 B

compressed-size-action

@carolinan
Copy link
Contributor

I tested different padding combinations in theme.json with emptytheme.
Padding on core/navigation > elements > link adds the same CSS as
padding on core/navigation-link > elements > link.
If they are added at the same time, which ever is placed last in theme.json "wins". I think this is the expected behavior but I thought I should mention it.

The page list is a separate block, but when I tried to style it with theme.json, the CSS output broke.
It is a separate issue.

@jasmussen
Copy link
Contributor Author

Thank you for testing! I would agree about expected behavior, and the separate issue of Page List. I ticketed #31879 for that one.

@jasmussen jasmussen force-pushed the fix/nav-specificity branch 3 times, most recently from 6adafc7 to 15b1288 Compare May 25, 2021 10:16
@jasmussen jasmussen requested a review from a team May 25, 2021 10:16
@jasmussen
Copy link
Contributor Author

Rebased this one. Although there are some big changes here, as noted, they are important. Moreover, this should be easy to test insofar as trunk and this branch should look and behave exactly the same.

@jasmussen jasmussen added this to 👀 PRs needing review in Navigation block May 31, 2021
// We use :where to keep specificity minimal, yet still scope it to only the navigation block.
// That way if padding is set in theme.json, it still wins.
// https://css-tricks.com/almanac/selectors/w/where/
.wp-block-navigation:where(.has-background) a {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nosolosw I wanted to make sure you saw this, as I think it's a trick we should use a lot with global styles, now that we don't have to support IE11.

Here's the situation. We want to provide a default menu item padding for menu items. Zero padding when there's no background, a relaxed padding when there is. We can do that like so:

.wp-block-navigation a {
	padding: 0;
}

.wp-block-navigation.has-background a {
	padding: 0.5em 1em;
}

Those are fine as default paddings. However, and as is the purpose of this PR, global styles aims to let you customize these paddings, and it outputs them, for example, like so:

.wp-block-navigation-link a {
    padding-top: 1.5em;
    padding-right: 2em;
    padding-bottom: 1.5em;
    padding-left: 2em;
}

Unfortunately, in the battle against .wp-block-navigation.has-background a, it will lose.

However using the where selector, it still wins:

Screenshot 2021-05-31 at 11 22 42

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created a simplified codepen to outline the method: https://codepen.io/joen/pen/abJVrGX?editors=1100

Copy link
Member

Choose a reason for hiding this comment

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

Oh, this is a very nice trick, thanks for sharing!

Thought a bit about how we could use this in the global stylesheet. Essentially, we output 1) block styles as block_selector { ... }, 2) blocks with elements, such as block_selector element_selector { ... }, 3) preset classes .has-value-preset_name { ... }, and 4) preset classes specific to a block, as in block_selector.has-value-preset_name { ... }.

This trick seems to be more appropriate for styles in the lower layers, such as this PR: styles that come with the block, whether it's added by core or a plugin. Is this your assessment as well? Do you see more opportunities to use this pseudo-class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This trick seems to be more appropriate for styles in the lower layers, such as this PR: styles that come with the block, whether it's added by core or a plugin. Is this your assessment as well?

Exactly. I recall our weapons-race eventually leading us to add !important modifiers to many global styles. While I can understand the potential necessity of that, I've been looking at ways to de-escalate that. And essentially, if we can reduce the specificity of all blocks and hopefully provide a pattern for themes to follow, that might let us reduce the specificity needed by global styles, and find a more harmonious balance. This codepen shows a basic example of a direction that could take:

html :where(.has-red-background-color) {
	background-color: maroon;
}

html :where(.has-green-background-color) {
	background-color: darkgreen;
}

These are default colors which, due to the where-selector has low specificity. In fact the specificity is so low that these classes, regardless of order in the stylesheet, will override them:

.has-red-background-color {
	background-color: red;
}

.has-green-background-color {
	background-color: green;
}

We might even increase the specificity of global styles in a different way, using the :is selector: https://css-tricks.com/almanac/selectors/i/is/

Copy link
Member

Choose a reason for hiding this comment

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

I find the use of !important in user-generated styles (preset classes, the only place we use them) still necessary and the rationale holds for me (user styles have higher priority than any theme or core style). However, I've been hearing in some places that allowing to hook into these user styles may be necessary in some cases (dark mode, media queries). What would you think of #32627?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your thoughts here. I think I like that PR, but I need to think about it even more — CSS variables are all the rage, and I think we may be over-using them in some cases. But yes, that would be a way to add theme control 👍 👍

The reason I worry about the use of !important is that it's nuclear, it's the last resort, and there are almost always situations where using it means some legitimate use case becomes moot. But using it with precision as we do now, and in very specific cases, that might be fine. And if we find out in the future that it isn't, we have some ideas on what we can try instead.

@jasmussen
Copy link
Contributor Author

In 390ab32 I moved the dropdown indicator inside the a tag. That profoundly simplifies the margin/padding rules, and lets the padding applied by global styles behave as intended:

Screenshot 2021-05-31 at 12 03 44

Compare that to this:

Screenshot 2021-05-31 at 12 05 30

As far as I can tell, this change does not appear to cause any deprecations nor does it appear to cause any other headaches with regards to appearance. Furthermore I don't see any accessibility problems with moving this as it already appears to have measures in place to hide it from screenreaders. Nevertheless I wanted to surface the change.

@jasmussen
Copy link
Contributor Author

Alright, I think this is ready for another review. It's refactored, and more heavily tested. I'll update the description with new testing content and more test cases.

Copy link
Member

@aristath aristath left a comment

Choose a reason for hiding this comment

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

I did a few tests and this seems to be working fine both in the editor and the frontend.
The code is sensible and I didn't find any issues.

As a side-effect, this also fixes issues when an outline is used on focus. For example in my theme I've got this:

a:focus {
    outline: 2px solid;
    outline-offset: 2px;
}

Before:

Screenshot from 2021-05-31 14-23-02

After:
Screenshot from 2021-05-31 14-23-48

I liked having the caret outside the link... It meant that the door is open to implementing on-click behaviors for menus (as opposed to the current on-hover, which I passionately dislike). However, this does fix an issue we currently have, so IMO we can merge it and see about on-click when the time is right.

@jasmussen
Copy link
Contributor Author

Thanks a ton for the review. I'm going to leave this one open for a bit still, to see if other folks have time to test and or share thoughts, and then depending on feedback I'll land this one tomorrow. It will enable some great followups I look forward to starting on.

I liked having the caret outside the link... It meant that the door is open to implementing on-click behaviors for menus (as opposed to the current on-hover, which I passionately dislike). However, this does fix an issue we currently have, so IMO we can merge it and see about on-click when the time is right.

Yes, I've been thinking a lot about how to best enable that in the future, and discussed it a bit in this thread. The short of it is that we'd probably either need to make it a split button, or a single toggle button anyway, needing to swap out some markup. So I think the split button is still possible if that's what we end up having to go with.

Thanks again!

@jasmussen
Copy link
Contributor Author

I'm going to land this and will as always follow up on anything that goes wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Block] Page List Affects the Page List Block CSS Styling Related to editor and front end styles, CSS-specific issues.
Projects
Development

Successfully merging this pull request may close these issues.

Navigation link CSS overrides defaults set using theme.json elements
4 participants