Make WordPress Core

Opened 8 months ago

Last modified 3 months ago

#60374 assigned defect (bug)

Twenty Sixteen: Navigation block inherits colors from button styles

Reported by: poena's profile poena Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Bundled Theme Keywords: has-patch needs-testing
Focuses: css Cc:

Description (last modified by sabernhardt)

Similar to #59924

The navigation block has an option called "Open on click" that is available when there is a submenu.

When the option is enabled, the parent menu item is a <button> element.
On the front of the website, this button inherits the background styles from the themes button CSS:

button:hover, button:focus, input[type="button"]:hover, input[type="button"]:focus, input[type="reset"]:hover, input[type="reset"]:focus, input[type="submit"]:hover, input[type="submit"]:focus {
	background: #007acc;
}

When the menu item is focused, activated or hovered over, the background color changes to blue.

Testing instructions:

  1. Activate Twenty Sixteen
  2. Make sure that your WordPress installation has some content that you can place in the navigation block, because you will need to create a submenu.
  3. Create a new post or page.
  4. Add a navigation block. In the block, select the inserter and add a link: this will be your parent menu item. Click on the link and select the option "Add submenu". Add a link.
  5. Save.
  6. Go to the front of the website.
  7. Locate the navigation and hover over or move focus to the item that has the submenu.
  8. Confirm that the background color of the menu item changes.

(You may also notice that if you set a background color on the submenu item in the block settings, this color only works in the editor, not the front, and this is a separate issue.)

Attachments (5)

60374.diff (833 bytes) - added by sabernhardt 8 months ago.
removes background, top and bottom padding, outline-offset and letter-spacing on buttons; removes side margins from submenus; adds side padding to modal
open-on-click-menu-button-before.png (6.9 KB) - added by poena 4 months ago.
With "Open on click" enabled on the navigation block, before patch
open-on-click-menu-button-after.png (4.7 KB) - added by poena 4 months ago.
With "Open on click" enabled on the navigation block, with patch
open-on-click-menu-button-after.2.png (4.7 KB) - added by poena 4 months ago.
With "Open on click" enabled on the navigation block, with patch
SCR-20240702-smrn.png (130.7 KB) - added by karmatosed 3 months ago.

Download all attachments as: .zip

Change History (25)

@sabernhardt
8 months ago

removes background, top and bottom padding, outline-offset and letter-spacing on buttons; removes side margins from submenus; adds side padding to modal

#1 @sabernhardt
8 months ago

  • Keywords has-patch 2nd-opinion added

The background, padding, outline-offset and letter-spacing needed to be updated for any button in the Navigation block. I also removed the margin on the submenu, making it work with LTR or RTL directions (without .rtl class). The open modal also need padding because the global CSS variables are not defined (likely the case in any classic theme).

Some of these styles should be changed in the editor's block styles instead of—or in addition to—theme edits.

On the other hand, maybe the Navigation block should not be supported inside the post content of a classic theme. It is not available in Widgets.

Issues in other bundled themes:

  • Twenty Thirteen has dark text on an orange gradient background in all states plus an extra top border on :active.
  • Twenty Fourteen has a green background with dark text on hover/focus.
  • Twenty Fifteen and Twenty Seventeen have a medium gray background with dark text on hover/focus.
  • See #59924 for Twenty Nineteen.
  • Twenty Twenty-One does not have contrast problems except when hovering over links in the modal, but the caret looks odd inside the button and the button's negative outline-offset makes it cover text.
Last edited 8 months ago by sabernhardt (previous) (diff)

#2 @poena
7 months ago

@sabernhardt

Hi
can you clarify this?

Some of these styles should be changed in the editor's block styles instead of—or in addition to—theme edits.

I am asking because it would need opening a new issue in the Gutenberg GitHub repository.

the global CSS variables are not defined

The navigation block uses --wp--style--root-padding* which does not seem to be included for classic themes. But the block should still use the 1rem padding from the clamp(), even when the variable is missing?

From the block's scss file (Gutenberg v 17.7.0):

// Try to inherit any root paddings set, so the X can align to a top-right aligned menu.
padding-top: clamp(1rem, var(--wp--style--root--padding-top), 20rem);
padding-right: clamp(1rem, var(--wp--style--root--padding-right), 20rem);
padding-bottom: clamp(1rem, var(--wp--style--root--padding-bottom), 20rem);
padding-left: clamp(1rem, var(--wp--style--root--padding-left), 20em);

#3 @sabernhardt
7 months ago

Thanks for opening GB59360; the modal padding was my main concern in Gutenberg. A few properties could be a problem in more than one theme (top and bottom padding, outline-offset and/or background), but it seems less likely now that changing any of those in the block styles would help.

This ticket was mentioned in Slack in #core-themes by karmatosed. View the logs.


5 months ago

#5 @sabernhardt
5 months ago

  • Keywords 2nd-opinion removed
  • Milestone changed from Awaiting Review to Future Release

#6 @karmatosed
5 months ago

  • Owner set to karmatosed
  • Status changed from new to assigned

#7 @karmatosed
4 months ago

@sabernhardt can you confirm you are happy for testing and to move this to being considered for release now then? I think that is the case but wanted to be sure.

#8 @sabernhardt
4 months ago

  • Focuses css added
  • Keywords needs-testing added
  • Milestone changed from Future Release to 6.6

Yes, it could be considered :)

#9 @karmatosed
4 months ago

  • Owner karmatosed deleted

@poena
4 months ago

With "Open on click" enabled on the navigation block, before patch

#10 @poena
4 months ago

I am not able to apply the patch, I copy pasted the CSS to the theme manually to test it.

grunt patch:https://core.trac.wordpress.org/attachment/ticket/60374/60374.diff
package.json has not been modified.
Running "patch:https://core.trac.wordpress.org/attachment/ticket/60374/60374.diff" (patch) task
patching file src/wp-content/themes/twentysixteen/css/blocks.css
Assertion failed: hunk, file ../patch-2.5.9-src/patch.c, line 354

The button element that is the parent menu item is not styled the same way as the link elements. There should be a bottom border that is hidden on hover and focus. The button is missing hover styles except for the mouse pointer. This border should only be added to this element, not other buttons.

The style that sets the background color on buttons to transparent removes the background color on the submit button in the search block.
Because the text color on the button element is white, the icon in the search block is not visible when the block is added to the navigation.

(It does not affect the submit button in the login/out block)

#11 @poena
4 months ago

  • Keywords changes-requested added

@poena
4 months ago

With "Open on click" enabled on the navigation block, with patch

@poena
4 months ago

With "Open on click" enabled on the navigation block, with patch

This ticket was mentioned in Slack in #core by oglekler. View the logs.


4 months ago

#13 @oglekler
4 months ago

  • Keywords needs-testing removed

This ticket was mentioned in PR #6829 on WordPress/wordpress-develop by @sabernhardt.


4 months ago
#14

  • Removes left and right margins from the opened submenu at larger screen sizes.
  • Resets styles for the submenu toggle (when it opens on click) plus the open and close buttons for the responsive container: background, border-radius, letter-spacing, outline-offset, and top and bottom padding.
  • Adds a box-shadow to match the link styles if: the Navigation block is within .entry-content, the submenu is set to open on click, and the toggle button is not in hover or focus state.
  • Adds a small amount of padding to the left and right sides of the responsive container when that is opened.

Trac 60374

#15 @sabernhardt
4 months ago

  • Description modified (diff)
  • Keywords needs-testing added; changes-requested removed

#16 @sabernhardt
4 months ago

  • Milestone changed from 6.6 to 6.7

Moving to next milestone for more time to test

#17 @karmatosed
3 months ago

  • Owner set to karmatosed

Assigning to myself so I can test with a possible view to commit based on what I find.

#18 @karmatosed
3 months ago

In testing this might be myself but I am unable to replicate the issue using the latest patch. I tried these settings, and it might be I am not replicating correctly, though.

#19 @karmatosed
3 months ago

  • Milestone changed from 6.7 to Future Release

#20 @karmatosed
3 months ago

  • Owner karmatosed deleted
Note: See TracTickets for help on using tickets.