-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Navigation Block: Fix link colors and remove unnecessary classes #25691
Navigation Block: Fix link colors and remove unnecessary classes #25691
Conversation
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.
Tested this and confirmed that it is now working reliably on the front end, whereas before custom background colors were not showing up for me. Nice work removing all that code!
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.
@aaronrobertshaw Thanks for working on this. I wasn't aware there was a bug, but checking master
text colors do seem to behave inconsistently (in TwentyTwenty some work and others don't).
Would be really helpful if you could share a bit more detail on what the changes are and why they were needed. The diff is fairly large and hard to follow without spending a lot of time on it.
An issue I noticed in testing is that submenu backgrounds are now transparent when no background is applied:
This is something that has regressed a few times previously, so would be great to get that fixed. 😄
@talldan Appreciate you taking the time to look at this one. Apologies for not providing enough info in the PR description. Overview of changesA lot of the diff is clean up of the unnecessary application of css classes and inline styles on the links when they can inherit them from the parent block. This allows a fair bit of code removal and avoids the need to pass those color attributes via the block context. The inconsistency of colors is a little trickier for me to articulate, so please bear with me 🙂 . When the color palettes and related named color css classes do not match between the editor and the frontend, what the user selects and sees in the editor turns out to be different than what is displayed on the frontend. I believe the extent of this issue is dependent on the theme and what it supports or provides. Given it was a problem across a range of themes, we should prevent a little frustration for our users and honour their selections where we can. As the useColors hook already provided actual color values we could just leverage those to set the inline styles forcing consistency between the editor and the frontend. Summary of changes per file
|
Thanks for providing details @aaronrobertshaw and fixing that issue, that really helps for review and also for anyone looking back at the history. The main part I'm uneasy about at the moment is the React hook that always sets custom colors. I feel as much as possible the nav block should stay consistent with the color systems used by other blocks. At the moment this PR changes that by setting inline styles even for named colors. Is this mainly a specificity issue or something else? |
@talldan I understand your unease on that hook always setting the custom colors. I feel a little the same way about it. The issue isn't with specificity really but consistency and ensuring the user gets what they asked for. As it is now, across many themes, the editor gets one color value for a named color class e.g. The poor user is left thinking they've selected one color and puzzled as to why a different color is shown when they view their site. As much as I don't like forcing inline styles and therefore those custom color attributes, I don't like making the excuse that it's the theme's fault when we could meet the user's expectations without too much trouble. The basis for this approach happened to be an earlier incarnation of the navigation link block where it was forcing inline styles in the editor. This is a bit of a problem in general with the current color system. If we had a means to force the consistency in named color css classes between the editor and frontend, I think we could avoid this. I might be missing something so if you have any suggestions I'm happy to alter the approach. |
@aaronrobertshaw I think rather than the nav block having ad-hoc code for handling colors (and more importantly markup in the frontend), consistency for blocks is best as a baseline. Once there's consistency, it makes it easier to look into improving the color system across all blocks. |
@talldan I’ve created an issue regarding achieving consistency of color selections between the editor and frontend #25889. The commit (8b84c42ef3955624cc2efad65a78bfb2afe717ab) that added the hook to force the inline styles has been reverted as well. What is left allows the color styles to cascade from the nav block to its links and removes a lot of otherwise unnecessary code e.g. passing of colors via block context. It also allows the editor to display the selected text color properly. |
This reverts commit 8b84c42ef3955624cc2efad65a78bfb2afe717ab.
Now block support css classes and styles are applied via the call to `get_block_wrapper_attributes`, the manual generation and application of them for colors and font sizes can be removed.
426a96e
to
becb122
Compare
I've rebased this and recent updates have solved some of the color consistency issues noted previously. Currently, it is just the navigation block suffering some inconsistency with link colors. During the rebase I noticed that duplicate CSS classes and styles were introduced (7c2fb7c) when the block was updated to use The PR description has been updated to included a more detailed breakdown of the included changes. Would you mind taking another look at this @talldan? |
Closing this as the underlying issues have been resolved elsewhere. |
Fixes #25889
Description
This improves the display of color selections for the navigation block between the editor and frontend. It also removes unneeded css classes and styles from the inner links allowing them to inherit the colors from the main navigation block itself.
Changes Included
packages/block-library/src/navigation/block.json
packages/block-library/src/navigation-link/block.json
packages/block-library/src/navigation/editor.scss
packages/block-library/src/navigation/style.scss
packages/block-library/src/navigation-link/edit.js
get_block_wrapper_attributes()
packages/block-library/src/navigation/index.php
packages/block-library/src/navigation-link/index.php
How has this been tested?
Manually tested.
Tried multiple themes and multiple color combinations between named and custom colors. Used a mix of full featured and basic themes. In particular the themes tested with were:
Testing Instructions
Screenshots
Before
After
Types of changes
Bug fix.
Checklist: