-
Notifications
You must be signed in to change notification settings - Fork 3
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
Stats on various ways of hiding DOM elements #7
Comments
On this matter, besides looking for the above CSS selectors and numbers, it would be interesting maybe to come up with some numbers on CSS declarations that "attempt" to hide elements too, e.g.:
Let me know what you think. |
I'm having trouble categorizing this in a section, @catalinred which section do you think it would fit in? |
I'd say the Selectors section maybe, we already have "How much are specificity hacks used? #27" so this might fit in there as well? If we're also interested in the above CSS declarations that "attempt" to hide elements, we can just add this extra information as a paragraph or two in there, even if it's not really related to CSS Selectors. |
Hmm, it looks like the metrics first comment relates to selectors, whereas the metrics in the second one do not, so I'm not sure Selectors would be a good fit. Perhaps we should step back for a moment and examine how we'd proceed with this metric and what it would teach us. For the selector component (1): How would we determine which classes to look for? Would the metric for most popular classes cover this, which is already going to be measured in the Markup chapter? Similarly, the usage of attributes like For the declaration component (2), what would we be measuring? How many rules use these? Which ways are more common? Or were you thinking of determining the selectors to look for from (2)? I.e. find which rules have a sole purpose of hiding elements and see which selectors for those are most popular? That could be really interesting, and yes, would fit quite nicely in Selectors. |
Even though most popular class names will be covered in the Markup chapter, most probably the top 10 or so will not contain any from the (1) point. In my opinion, a discussion about the presence of these classes wouldn't be that interesting in the Markup chapter but more in the CSS chapter because most of these class helpers are/can be added by libraries and/or popular CSS resets. But clearly, it's up to you :)
On the (2) point, indeed, initially, I was thinking about how many CSS rules contain at least one of the declarations (block) above but I find your idea interesting. Still, I think that e.g. you will never see |
Agreed.
At least one, or only such declarations? In the first case we'd get elements that happen to be hidden, whereas in the second, we'd get classes like the ones in your first comment, that have the sole purpose of hiding.
Especially about |
That's correct, only such declaration blocks.
This sounds good and looking forward to see the numbers! |
@LeaVerou here's an interesting find by @Tiggerito on the above |
So in terms of an algorithm, how about this: |
I'm afraid we may have to forgo this. Way too many false positives for the data to be interesting. If anybody else wants to work on it, here's my prototype: export default function compute() {
let ret = {};
walkRules(ast, rule => {
// Remove hiding declarations and see if there's anything left
let nonHiding = rule.declarations.filter(({property, value}) => {
if (property === "color") {
return !matches(value, [
"transparent",
/^(rgb|hsl)a\(.+?,\s*0\)$/,
/^(rgb|hsl)\(.+?\/\s*0\)$/,
/^#[a-f0-9]{6}00$/
]);
}
if (property.startsWith("-")) {
return false;
}
let str = property + ": " + value.trim();
return !matches(str, [
"display: none",
"visibility: hidden",
"overflow: hidden",
"clip: rect(0, 0, 0, 0)",
"clip: rect(1px, 1px, 1px, 1px)",
"clip-path: inset(0% 0% 100% 100%)",
"clip-path: inset(0px 0px 99.9% 99.9%)",
"transform: scale(0)",
"width: 0",
"height: 0",
"padding: 0",
"border: 0",
"opacity: 0",
"text-indent: -9999px",
"position: absolute",
"position: fixed",
]);
});
if (nonHiding.length === 0 && rule.declarations.length > 0) {
for (let selector of rule.selectors) {
incrementByKey(ret, selector);
}
}
}, {
type: "rule"
});
return sortObject(ret);
} I'm going to close it for now, but we can always reopen if there's a volunteer to work on it. |
Would like to see numbers on various ways of hiding DOM elements, by trying to guess on:
[aria-hidden]
,.hidden
,.hide
,.sr-only
,.visually-hidden
,.visuallyhidden
,.invisible
or[hidden]
.(by @catalinred)
The text was updated successfully, but these errors were encountered: