Problem/Motivation
There are a number of icons in the navigation module that contain hard-coded color values, which makes them behave poorly in dark mode or whenever users are attempting to implement them in non-standard contexts.
Update: In reference to my later comment in #7, the icons work fine in light or dark mode so long as they are given a magic CSS class at render time. If that class is omitted, however, as in the case of any custom implementation, the icons do no respect currentColor conventions.
Steps to reproduce
After a quick search of the navigation module codebase, I've determined that the following svg files have hard-coded colors that could stand to be changed to "currentColor". However, we should be absolutely sure that we've done some testing before just changing them; I imagine that some icons may have a two-tone color palette on purpose to communicate a certain message.
- radioactive.svg*
- signpost.svg
- warning.svg
- error.svg
- database.svg
- file.svg
* the radioactive icon is stored in the tests directory of navigation. Do we need to change this file or would it cause a testing regression?
Proposed resolution
Change hardcoded values to currentColor
Remaining tasks
Screenshots
#7 radioactive-after-dark.png 2.25 KB abenbow
#7 radioactive-after-light.png 2.26 KB abenbow
#7 radioactive-before-dark.png 2.26 KB abenbow
#7 radioactive-before-light.png 2.21 KB abenbow
#7 icons-dark-after.png 6.55 KB abenbow
Review
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | radioactive-after-dark.png | 2.25 KB | abenbow |
| #7 | radioactive-after-light.png | 2.26 KB | abenbow |
| #7 | radioactive-before-dark.png | 2.26 KB | abenbow |
| #7 | radioactive-before-light.png | 2.21 KB | abenbow |
| #7 | icons-dark-after.png | 6.55 KB | abenbow |
Issue fork drupal-3624877
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
abenbowComment #4
abenbowI've updated the above icons so that they use currentColor for the fill attribute.
In all cases above the fill color was #000000, or black, which seemed like it would play poorly with dark mode.
The only icon I didn't modify was eye.svg since there is another issue open specifically to address that.
See: https://www.drupal.org/project/drupal/issues/3623811#comment-16779480
Comment #5
abenbowMaking a note here that I intend to upload some screenshots in a moment demonstrating the difference between the old and new icons so the color differences are apparent.
Comment #6
ironnuts commentedHi abenbow, I am following this issue. Just reviewed the related issue. Will try to review when you can upload the screenshots.
Comment #7
abenbowHere are the promised screenshots showing the before and after of the icons in the navigation sidebar.
There is no noticeable difference between the before and after because, as I've discovered, the navigation icons render using the .toolbar-button__icon CSS class, which has has a fill: currentColor rule. This takes care of toggling between the colors in light mode and dark mode even if the SVG doesn't use currentColor. In this case, my MR just focuses on the SVG file value, which has the added effect of making these SVGs more portable if that class name is omitted (as in the case of a custom implementation).
Currently, a user implementing a core icon for a custom purpose has to knowingly call the twig component pattern for icons and also pass a specific settings array into that builder in order to get an icon that respects currentColor, which means that they also have to inherit and override parts of the navigation CSS in order to get access to custom styling.
Here is a sample implementation from my own testing
As for the "radioactive" icon in the test suite, I want to note that the icon appears to be a clone of the "error" icon but with a different name.
Furthermore, it is only used in one context, NavigationTestHoohs.php, specifically for the purpose of discovering newly added icons to an icon pack. In this context, the proper toolbar-button__icon class is never added to the render hook, so the icon does not get rendered with the CSS-implied currentColor rule, and therefore is never tested in a visual capacity. It follows that the fact that I altered the SVG to include the currentColor rule should have no impact on tests.
My defense for retaining the change to his very niche corner case is in terms of improving navigation's best practices for the frontend. SVGs should carry the burden of adapting to their context by default, and CSS should only be used when that default is not sufficient.
Comment #8
smustgrave commentedCan the summary please use the standard template.
Comment #9
abenbowAdapted the issue summary to the standard template.
Comment #10
abenbowAlso updated the summary somewhat to reflect my discoveries in #7.