Description
Mint makes it pretty clear that selectors are not reliable by showing the following message in the console, in all Caps:
!!!DO NOT TARGET ELEMENTS WITH SELECTORS BECAUSE THE SELECTORS WILL BE MINIMIZED IN THE PRODUCTION BUILD!!!
I actually think it's really nice that Mint deals with minifying stuff for me, and usually the information in the learn section is sufficient to clear any doubts (https://www.mint-lang.com/guide/getting-started/styling-with-css and https://www.mint-lang.com/guide/reference/components/styling-elements for CSS, and also https://www.mint-lang.com/guide/reference/components/referencing-entities). But in some rare situations I find information that implies there's more to this issue than would appear. A good example is https://www.mint-lang.com/guide/recipes/using-third-party-css where classes are used.
One specific scenario that worries me is when I need to modify something that is inside a component, let's call this "Child component", from another component, let's call this one "Parent component", and to clarify what I mean, let's consider a parent component "Main" which creates a header and a footer, and it includes a Child Component "Searchbox" both in the header and footer, only for the footer version it would like to set the opacity for the search box to 0.7, reverting to 1 only when the search box is hovered. Or, to use something I actually wanted to do as an example, making Mint-Ui's Ui.Native.Select
full-width (100%
, 100vw
, whatever you fancy). Here's the documentation for Ui.Native.Select
, just to reinforce the point that it doesn't mention any way to set its width: (https://ui.mint-lang.com/components/ui-native-select).
When dealing with mint component
s there's no simple way to target a child element, especially in more complex elements that may have multiple div
s at each nesting level, and having to use some unreasonably long combination of >
s and nth-child
s doesn't make a lot of sense to me, but then there's no mention anywhere in the docs of any easy way to target stuff inside a child component, which brings me to the point of this issue:
What would be the preferred way to deal with this kind of situation (Or is this something that has no established solution)? What are the actual limitations when using selectors? Some examples of those limitations would be:
- Are ids changed/minified/replaced/substituted? (I'll try to only use "substitution" from now on)
- And what about classes?
- When the substitution is made, it appears external stylesheets and
class
es in the html are synced, what else is and isn't synced? - Are sub-rules in
style
blocks checked to sync the class names? - What about values passed to
Dom.getElementById
andDom.getElementBySelector
?- Is there some other factor involved here (And/or in any other case), such as whether the value comes from a variable or is a literal that appears on the code together with this function call...?
- External stylesheets?
- Inline JavaScript code...?
This issue is actually a minor one, but it hurts to have no centralized, indexable source of truth about this, which is actually considered so fundamental that it deserves to be shown at the DevTools every time the browser loads the project in dev mode. The documentation about selectors is spread throughout many different sections and in very small chunks, plus it has some conflicting information (i.e., The use of classes when working with external CSS), and even worse than that, the docs mention the use of classes only superficially, without any further clarification about what actually works and doesn't work.
All things considered, at the very least I wanted to compile the references and whatever information I could think of here, as an issue, so anyone can contribute to make those things clear, and so that this may lead to, at some point in the future, improving the documentation.