Closed (outdated)
Project:
Drupal core
Version:
9.3.x-dev
Component:
Olivero theme
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
19 Jun 2020 at 11:53 UTC
Updated:
1 Jul 2021 at 19:42 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
nod_we prefer using data- attribute for JS related selection, that way themers are free to do whatever they need with classes without breaking the JS. It came up a few times the past weeks so something must not be clear on core side.
Essentially: js- prefix: better than a "simple" class, dedicated data- attribute = best.
Comment #3
mherchelComment #4
mherchelThanks!
Comment #5
mherchelComment #6
thedrupalkid commentedComment #7
thedrupalkid commentedAs I see we are adding data attribute for js classes, I have spent some time looking for the classes which actually needs to be prefixed but found either they already have a data attribute or they are used both in CSS as well as js. Can you guys point to what more to be expected in this issue?
Comment #8
Pooja Ganjage commentedHi,
I am applying patch for adding js prefix class in js files.
Kindly review once.
Comment #9
thedrupalkid commentedHey @Pooja, We have to update the DOM also with the same changes but that is not needed until and unless the class is used only in js, as @nod_ also commented they prefer data- prefix. Please read my above comment as this will not help us updating the prefixes as they are used in js as well as the same classes are used in CSS.
Let me provide you an example if we change .site-branding__inner class it is used in the below template.
/olivero/templates/block/block--system-branding-block.html.twig
Now if you are updating in js DOM also needs to be updated and the same class we are using here is CSS line number 79, it will break if you update the class in DOM.
/olivero/css/dist/components/header-site-branding.css
My concern is the same in the above comment:
Comment #10
Pooja Ganjage commentedYes you are right, but can I provide different css file name for js file.
Comment #11
thedrupalkid commentedLet's wait for maintainers comment, I'll try to connect via slack with them.
Comment #12
Pooja Ganjage commentedOkay
Thanks
Comment #13
mherchelThanks for working on this!
If the classes are used in CSS, the class name needs to be left as is, and add data attributes or
js-prefixed class names as needed.If you already see a data attribute, you should use this in the JS. Many of the templates were copied over from themes such as Claro and Classy, so the data attributes may already exist.
Comment #14
thedrupalkid commentedWelcome @mherchel, Let's me scan through all the js specific attribute and add prefixes.
Comment #15
Pooja Ganjage commentedHi,
I am applying patch for this issue.
Kindly review the patch once.
Thanks.
Comment #16
mherchelThanks for the work @Pooja Ganjage
We only want to change the selectors that the JavaScript is querying. We do not want to make changes to the CSS.
So, you'll need to add additional data attributes (or classes) into the DOM, and then make changes to the JavaScript to use these new attributes or classes. Please do not make changes to the CSS.
Comment #17
mherchelLooking further at the patch, I think you only did a search and replace. Did you test your patch yourself?
Comment #18
thedrupalkid commentedI have scanned all the classes and working on a patch now. Moving all the required classes to js- prefix.
Comment #19
thedrupalkid commentedHello @mherchel, I have scanned all the js files and applied the prefix in the patch. Please review.
here is the approach I have followed and made changes
All other files either have the js prefix or do exist in css to which the change is not required.
Comment #20
thedrupalkid commentedPlease review this one as the above is not related and uploaded by mistake.
Comment #21
thedrupalkid commentedRemoving new line change in this patch.
Comment #22
Pooja Ganjage commentedHi,
thedrupalkid you missed some where to include js prefix class.
I am applying updated patch.
Kindly review once.
Let me know for any correction.
Thanks.
Comment #23
thedrupalkid commented@Pooja: Thanks for the patch, as Mike has suggested testing changes before creating a patch will be beneficial and the additional changes will break the js functionality as we are using it in CSS as well as in DOM.
Changes to this:
Also used on page.template.twig which is very generic and break everything:
Also changing this
will affect this:
So these additional changes are not required.
Comment #24
Pooja Ganjage commentedOkay Thanks @thedrupalkid for your suggestions.
Comment #25
Pooja Ganjage commentedComment #26
mherchelComment #27
Pooja Ganjage commentedHi,
I am creating a patch for this issue on 9.1.x-dev drupal version.
Please review the patch.
Thanks.
Comment #28
Pooja Ganjage commentedComment #29
mherchel@Pooja Ganjage Please be sure to test your patches before submitting them.
There are a couple problems with this patch:
1. You changed the selectors, but you didn't change the markup. This will break the functionality.
2. See @nod_'s comment in #2. We should try to use
data-attributes instead ofjs-prefixed classes.Comment #30
Pooja Ganjage commentedupdated patch.
Comment #31
mherchel@Pooja Ganjage Once again, please be sure to test your patches before submitting them. The classes that you are adding do not exist. We also want to move away from classes and use data attributes (not
data-prefixed classes) as selectors.Comment #32
mherchelComment #33
sarvjeetsingh commentedI have set a data attribute instead of class 'show-hide-wrapper'.
Comment #34
mherchelWe need to make this changes to all JS selectors, not just one.
Comment #35
Pooja Ganjage commentedHi,
Creating a patch to including changes to JS selectors.
Kindly review the patch.
Let me know if any suggestions.
Thanks.
Comment #36
Pooja Ganjage commentedComment #38
paulocsComment #39
paulocsmessageWrapper.setAttribute('data-messages-list__item messages messages--', "messages-list__item messages messages--".concat(type, " messages-processed"));which attribute is
data-messages-list__item messages messages--? I'm not sure how to replace it, but it is seems wrong like that.Comment #40
Pooja Ganjage commentedComment #41
Pooja Ganjage commentedComment #42
mherchel@Pooja Ganjage The selectors are what needs to be changed, not the CSS classes that are being modified. The patch that you submitted will break a lot of functionality. Did you test this?
I appreciate the enthusiasm, but in the future, can you please attach videos of the changes working properly when submitting a patch?
Comment #43
agarzola commentedHi. I think I understand what needs to happen here. How would you feel about using
data-olivero-*attributes for these selectors? I think it would be beneficial to set a convention whereby not only do we usedata-*attribute selectors (a direction which I very much support), but we go one step further and scope these selectors to be Olivero-specific by using anolivero-prefix (hencedata-olivero-*). This is not unlike Drupal’s owndata-drupal-*attribute selectors (data-drupal-nav-tabs, for instance).I’ve created a very contrived patch that accomplishes my proposed solution for the selectors in
tabs.es6.jsas well as associated template files to get opinions on this direction. Please bear in mind this is by no means an exhaustive patch; it is only meant to illustrate how this idea would look before spending any significant amount of time on this.I look forward to hearing your feedback. Thanks!
Comment #44
markdorisonRe-rolled patch in #43.
Comment #45
pcate commentedI think this could cause confusion down the line for themes that use Olivero as a base theme, or use a contrib theme that uses Olivero as a base theme. I'm thinking particularly of how extensively classy is used by custom and contrib themes as a base theme.
Also, if this naming convention was used for attributes in a JS theme function (which can be overridden by a theme), this could break functionality. While that could technically happen with any
data-attributes, having the theme name in the attribute might give the mistaken impression that they are not needed or should be changed to include the theme's name. e.g.data-awesome-theme-*If using an additional identifier for
data-attributes is needed, I would prefer a more generically named one. Is there a reasondata-drupal-*should not be used? I'm not sure if that convention is only supposed to be used for core modules.Comment #46
pcate commented@mherchel would it perhaps be better if this issue became a meta issue and separate sub-issues were created for the changes to each JS file (and associate twig template)? It might make it easier to review changes, test, and spread out the workload.
Comment #47
agarzola commentedGood point, @PCate.
This is why I was reluctant to suggest
data-drupal-*, but given the points you stated above, I’m inclined to suggest we move forward without scoping (i.e.data-*).---
Creating separate tasks for each JS file in the theme makes sense, especially from a reviewing/testing perspective. Happy to contribute to this issue further once we have a definitive way forward!
Comment #48
mherchelAgree that this should be a meta issue. Converting it to one now.
Comment #49
mherchelComment #50
mherchelComment #51
mherchelComment #52
mherchelComment #53
mherchelComment #54
mherchelComment #55
mherchelComment #56
mherchelComment #57
mherchelUpdating status
Comment #58
catchIs it just #3212975: Olivero: Normalize JavaScript selectors in messages.es6.js left to do here? If so should we switch out the issues on #3177296: [META] Make Olivero stable and close this meta?
Comment #59
mherchelDone!