Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Follow-up to #1342054: [META] Clean up templates and CSS
Problem/Motivation
- Bartik's template files need to be assessed and cleaned up of redundant markup, bad formatting and ID's.
- Bartik's CSS files need to follow Drupal's CSS Coding Standards.
Proposed resolution
For this issue we take "primary-menu.css" within Bartik in css/components/primary-menu.css plus any template file associated with the CSS and clean them up.
Remaining tasks
- Write a patch containing as much as the above as possible.
- Post a patch with screenshots.
- Visual review of a patch - check the secondary menu visually with and without patch applied. Take screenshots.
- Code review of a patch - check the code follows coding standards, suggest improvements if needed in a comment.
- Produce a new patch with improvements if needed.
User interface changes
None
API changes
None
Data model changes
None
Beta phase evaluation
Issue category | Task because it is refactoring CSS and templates in Bartik |
---|---|
Issue priority | Not critical because Bartik functions fine we are just doing cleanup tasks |
Unfrozen changes | Unfrozen because it only changes CSS and markup |
Prioritized changes | The main goal of this issue is usability of the Bartik's codebase |
Disruption | non-Disruptive as it is just changing markup and CSS |
Comment | File | Size | Author |
---|---|---|---|
#71 | interdiff_70-71.txt | 1.24 KB | IndrajithKB |
#71 | 2502045-71.patch | 9.07 KB | IndrajithKB |
#70 | interdiff-69-70.txt | 1.99 KB | Gauravvvv |
#70 | 2502045-70.patch | 9.77 KB | Gauravvvv |
#69 | 2502045-69.patch | 9.76 KB | kiran.kadam911 |
Comments
Comment #1
emma.mariaObservations of the primary-menu.css file.
We should not name CSS selectors based on the location the component is sat within. What if someone wants to move the Primary menu? I know that we have a specific region for it in Bartik but it's bad practice for CSS. It causes really long overspecific selectors such as
.region-primary-menu .block-menu .menu
which we can improve.Therefore we need to come up with a solution to be able to apply styles using a resuable component class such as
.primary-menu
or.primary-menu--block
(name to be decided based on the component it is added to) instead.We also need the usual clean up of comment formatting within the CSS file also.
Comment #2
emma.mariaComment #3
mgiffordThanks for championing this @emma.maria
Can this be done in 8.0?
Comment #4
dcrocks CreditAttribution: dcrocks as a volunteer commentedComment #5
dcrocks CreditAttribution: dcrocks as a volunteer commentedThis patch appears to work but please test. Since the class name menu--main uses the menu's machine name drupal guarantees that it is unique and so it is a good selector. But please note that since the region css components contain so much styling that this and the secondary menu will look different in each region it is placed, which is probably what should happen. And the corollary is that any block moved to these regions will also look differently than in their original placement.
Comment #6
emma.maria@dcrocks thanks for the patch!
The issue we need to solve here is to not rely on the region markup or limit the styles to one particular instance of menu. We want any menu added to this region to have the "main navigation" styles. The default provided main navigation also should not look the same wherever it's placed, the styles should default to basic menu list styling elsewhere.
Therefore we need to add a reusable component class to menu blocks when they are added to the currently named "Primary menu" region and amend the current CSS to use that class.
Comment #7
emma.mariaComment #8
emma.mariaComment #9
emma.mariaComment #10
emma.mariaI have kicked off the work needed for this issue.
I have added two classes to a brand new template for the Primary menu region in Bartik called region--primary-menu.html.twig
These classes are:
.layout-primary-menu
is for Primary menu region layout styles..primary-menu
is the component class for the styling to make a menu look like the tab style menu that we have for the main navigation of Bartik.Further work needs to be carried out with this patch. I think menu-toggle styles might be able to be moved out to their own files.
There is also an awful lot of CSS overriding each other so that would be good to investigate also.
Comment #11
lauriiiInstead of overwriting whole template why not just simply:
Comment #12
emma.mariaThanks @lauriii. Let's change the contents of region--primary-menu.html.twig to what is in #11.
Comment #13
pjbaertUpdated the region--primary-menu.html.twig as requested in #12
Comment #14
dcrocks CreditAttribution: dcrocks as a volunteer commentedThis patch implements the suggestion in #11 and breaks the toggle code into a separate file. I'm not quite sure what the boundaries are there though. It needs more work. For example, is the assumption that block labels are invisible in these menu areas true?
Comment #15
emma.mariaThe mobile menu has space either side of it.
This is because of the following code which is needed for the other displays of the menus.
Can we amend this so the padding is only applied to widths above when the mobile menu is used please.
Comment #16
emma.mariaComment #17
rudraram CreditAttribution: rudraram at Axelerant commented@emma.maria Uploading the re-rolled patch for #14. Attaching screenshot too.
Comment #18
rudraram CreditAttribution: rudraram at Axelerant commentedAbove patch committed the changes for the new files. Updated and uploading. Interdiff attached.
Comment #19
rudraram CreditAttribution: rudraram at Axelerant commentedComment #20
rudraram CreditAttribution: rudraram at Axelerant commentedComment #21
rudraram CreditAttribution: rudraram at Axelerant commentedMy internet really went crazy and created all the mess above. Sorry for all that. Please ignore comments from #18 - #20.
This #21 has all the final patch re-roll updates + screenshot.
Comment #22
pjbaertComment #23
rudraram CreditAttribution: rudraram at Axelerant commentedComment #24
emma.mariaThanks @rudraram I will take a look at the patch in #21.
Comment #25
emma.mariaThanks @rudraram the menu looks great.
I have seen some code improvements.
As the primary-menu toggle is a variant of the primary menu the styles needs to go back into primary-menu.css.
For eg...
This rule is present in our coding standards, media queries are a state of a component and not a component themselves.
body:not(:target)
amongst the selectors. This was originally used to provide browser support for the menu dropdown and we should see if this is still needed for IE9+.from http://www.creativebloq.com/netmag/build-smart-mobile-navigation-without-hacks-6126265 in 2012.
Comment #26
dcrocks CreditAttribution: dcrocks as a volunteer commentedThis patch is just to reset the patch. It goes back to when the toggle code was part of primary-menu.css and adds a @file statement to it. The code seems to very fragile, as simply moving hunks of code around breaks the layout pretty badly.
Comment #27
dcrocks CreditAttribution: dcrocks as a volunteer commentedComment #28
dcrocks CreditAttribution: dcrocks as a volunteer commentedThis is a small fix because of a visual regression introduced by this patch. The css here seems very fragile.
Comment #29
thamasI just started to check this issue and wonder why we have the name of the primary menu region from its default content? It should have a more generic name maybe just as the Messages region was renamed to Highlighted.
Comment #30
dcrocks CreditAttribution: dcrocks as a volunteer commentedSee #2513526: Rename the menu regions
Comment #31
thamasThanks @dcrocks for pointing the related issue.
Comment #32
thamasFix misleading part of issue description possibly coming from the creating of the issue by cloning an other one.
Comment #33
thamasAbout the last patch in #28
:target
selector is supported by IE9 (as well as all other current browsers) sobody:not(:target)
selectors should be removed from the code (see also #25).Comment #34
thamasRedundant, already defined at line 8–9
Redundant. Already defined at line 19-20.
Redundant. Already defined at line 7.
There could be more redundant code like these.
Also the declaration order in the rulesets should be set aligned to our standards.
Comment #35
thamasOtherwise I am totally confused by this issue.
The title says we want to
However Primary menu is a region. If I move its html code to somewhere else its content will not look like the same (using the current patch).
Later @emma.maria writes in #6 that
and
However what the current patch do is adding a new class
.primary-menu
to the region and using that class to style menus instead the original.region-primary-menu
class. I can't see the difference why it is better?If we want to to style menu block when they are in this specific region, the current (not patched) solution just works.
If we want to be able to style a manu to look like the current main menu in the primary region independently from its position than we should create a menu--primary modifier for the menu component and make it possible to apply that class to menu blocks when it is needed.
Comment #36
dcrocks CreditAttribution: dcrocks as a volunteer commentedA good question. The fact is, for bartik, menu styling is different for different regions. So yes, the menu styling is tied to the region but that styling shouldn't be tied to the region name, as other content might go into a given region. So this patch provides a region twig file to identify the menu styling for this region. That file's name will change when the region does get renamed but the menu classes added wont.
Just a note, removing all the 'body:not(:target) selectors' doesn't seem to introduce any visual regression on firefox at least and also removed the redundant code mentioned in #34. I'll provide a new patch soon.
Comment #37
dcrocks CreditAttribution: dcrocks as a volunteer commentedThis removes all the 'body:not(:target)' selectors. However just moving multimedia code around introduces visual regressions. That will take more thought.
Comment #38
dcrocks CreditAttribution: dcrocks as a volunteer commentedThe last is not going to work.
Comment #39
dcrocks CreditAttribution: dcrocks as a volunteer commentedThis design is mobile 1st. Removing toggle code causes visual regressions. Dispersing media code causes visual regressions. I would like to go with #28 and if someone thinks serious css improvements need to made then that could possibly be a follow up issue.
Comment #40
dcrocks CreditAttribution: dcrocks as a volunteer commentedRemoved all 'body:not(:target)' selectors. This time did it correctly. Tried in firefox, chrome, safari, and opera. Appears to work OK.
Comment #41
dcrocks CreditAttribution: dcrocks as a volunteer commentedThis disperses the multimedia code thru-out the file.
Comment #42
thamas@dcrocks Thanks the info and the patches. I try to check them (if I have enough time)
About the issue: so the idea is that the region name will change but it will keep the currently introduced .primary-menu class? If so that will be confusing. It basically not the best idea to modify the styling of a component (menu) because of its position in the layout (.region-name .component name {sepcific: styling;}) – but if we do so, it is much better to use the name of the layout element then introduce a new class which is hard to identify. (The recommended and reusable way would be to add a modifier to the component: .menu--primary.) I just not understand how will .primary-menu be reusable. Also how other elements than menus in this region will be styled? Will they have an other class?
Sorry if these all clear to others. I try to understand it…
Comment #43
dcrocks CreditAttribution: dcrocks as a volunteer commentedThere is a lot of history there. This is my understanding of it. The bartik theme, and the Gardner theme before it, always had 2 menus in the header area. The variable names used to place them were 'primary-menu' and 'secondary-menu'. These menus are identical in output to the 'User account' and 'Main navigation' menus but they have a special use case in which they could be joined to make one multilevel menu. I've never used that option but apparently a lot of others have.
In drupal 8, these menus were converted to blocks while still preserving the special use case. That was part of the effort to eliminate system variables in templates, which you can see in many other issues. In the process of creating these blocks the header area was broken into 3 regions with the current names.
But those names don't meet standards so there is an effort to rename them. And it is also a standard for any menu placed in a given region to have a styling appropriate to that region's over all design requirements. For the header area, in what are now called the primary- and secondary- menu regions, the styling for any menu has to match the historical primary and secondary menu styling, upgraded to support mobile devices.
The purpose of this issue is to free that styling from the name of the region while still maintaining the historical connection to the primary and secondary menus. When the issue is complete, any menu placed in this region will have the same styling. It is also intended as part of a general cleanup that is being down on all core css.
I hope this helps. I hope there isn't any major error in fact or interpretation, but hopefully others will correct me.
Comment #44
dcrocks CreditAttribution: dcrocks as a volunteer commentedI do agree that the term 'reusable component' is confusing here. We are really providing standardized styling for one particular 'type' of block in this specific region.
Comment #45
dcrocks CreditAttribution: dcrocks as a volunteer commentedHere is an example of the Tools menu added to the primary menu region.
Comment #46
thamas@dcrocks Thanks for not giving up explaining the issue for me!
Comment #47
thamas@dcrocks Thanks for your patch! While I still have concerns about the issue I used your patch as a base for refactoring and cleaning up more the file. The result of our effort is 175 lines instead of 193 and 3.7 KB instead of 4.7 KB. :)
So it still needs review and the one who review it please read our discussion about the goal and the solution of this issue.
Comment #48
dcrocks CreditAttribution: dcrocks as a volunteer commentedDid a new git clone of 8.0.x and applied patch from #47. Installed cleanly and saw no visual regressions. Did notice that both the 'Place block' and 'Configure block' form allow you to toggle the 'Display title' option, which means you can change that option on both new menu placements as well as existing ones. Takes care of my issue with that feature.
Comment #49
dcrocks CreditAttribution: dcrocks as a volunteer commented@thamas I know you have other things to do, but could you take a look at the sister issue, #2502049: Replace the "Secondary menu" component with a reusable component in Bartik. if you have time?
Comment #50
thamas@dcrocks I can't promise it very soon, but I'll check that.
Back to this issue I wonder why we do not have
.menu__link
classes because styling html elements (in this case thea
element) is not a good practice…Comment #51
dcrocks CreditAttribution: dcrocks as a volunteer commentedStruggling to find generic way to add class menu__link to 'a' elements of components of type primary-menu. Complicated by fact that a special class 'is-active' is added to all menus but by different means if anonymous or logged in users(php vs javascript). So far, can't prevent visual regressions. Added screenshots.
Comment #52
dcrocks CreditAttribution: dcrocks as a volunteer commentedI don't think etiquette allows me to mark this RTBC but I think #47 meets all the requirements specified in the issue summary and in discussion. As far as providing a class name for 'a' elements, the only way to properly solve it is as a generic issue for all drupal css, not just for the primary menu.
Comment #53
thamasWhile I think this issue should be RTBC here is some addition to my toughts in #42:
Harry Roberts, in Contextual Styling: UI Components, Nesting, and Implementation Detail (see the Implementation detail part for, ehm… details :)).
Comment #54
dcrocks CreditAttribution: dcrocks as a volunteer commentedRerolled this for current 8.1.
Comment #55
dcrocks CreditAttribution: dcrocks as a volunteer commentedDid that wrong. This is a patch against current 8.0.
Comment #64
djsagar CreditAttribution: djsagar at OpenSense Labs commentedHi,
The patch of #55 is not working here is the screen short which can be help to find the error.
Thanks!
Comment #65
ankithashettyHi @djsagar, looks like you applied the interdiff text file instead of the patch file...
Here's the re-rolled the patch in #55 against the 9.1.x dev branch.
Thanks!
Comment #69
kiran.kadam911Thanks to everyone for the patch. It's applied successfully.
Here's the re-rolled the patch in #65 against the 9.3.x
Thanks!
Comment #70
Gauravvvv CreditAttribution: Gauravvvv at OpenSense Labs commentedI have attached a patch and interdiff as well. Please review.
Comment #71
IndrajithKB CreditAttribution: IndrajithKB at Srijan | A Material+ Company for Drupal India Association commentedHi @Gauravmahlawat thanks for the patch, here am re-rolling the patch by resolving the custom failures, please review the patch
Comment #74
DeepaliJ CreditAttribution: DeepaliJ at Salsa Digital commentedComment #76
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge require as a guide.
Reviewing the last patch this appears to be bartik specific. Bartik was removed in Drupal 10 so moving this ticket to the contrib module
Comment #77
DeepaliJ CreditAttribution: DeepaliJ at Salsa Digital commented