-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
report(redesign): add toggle control to show metric descriptions #8661
Conversation
</div> | ||
<div class=""></div> | ||
</div> | ||
</summary> | ||
</details> | ||
</template> | ||
|
||
<!-- Lighthouse metrics toggle --> | ||
<template id="tmpl-lh-metrics-toggle"> | ||
<div class="lh-metrics-toggle"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd like to use a <input type=checkbox>
here (as the underlying control).
we shouldn't need JS for this guy (except for this.metricAuditGroup.classList.toggle('lh-audit-group--metrics__show-descriptions')
)
this guide seems to be solid on implementation.. also including their resources at the bottom. https://webdesign.tutsplus.com/tutorials/how-to-make-custom-accessible-checkboxes-and-radio-buttons--cms-32074
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, hows that?
<defs> | ||
<path id="a" d="M0 0h24v24H0V0z" /> | ||
</defs> | ||
<clipPath id="b"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
afaik this clippath isn't being used. i guess its just an artifact from sketch exports.
<div class="lh-metrics-toggle-more"> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"> | ||
<path class="lh-metrics-toggle-lines" d="M3 18h12v-2H3v2zM3 6v2h18V6H3zm0 7h18v-2H3v2z" /> | ||
<path fill="none" d="M0 0h24v24H0V0z" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto with this unused path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx! this is def looking in the right direction.
apologies i'm finding so much in this one.
this.metricAuditGroup = this._dom.find('.lh-audit-group--metrics', this._document); | ||
} | ||
|
||
_setupMetricDescriptionToggleListeners() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i definitely didnt expect this..
click on the newly expanded descriptions to make them go away?
this UX doesn't make sense to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this would only make sense if the toggle is scoped to just the metric title.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
silly that u cant link to doc comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aiight. i'm not feeling this UX at all, so I raised a concern there: https://docs.google.com/a/google.com/document/d/15L5iaWo4ieouegpSlaqGGWpA13JnTv73xnpxuVhzkBg/edit?disco=AAAAC6njMnI
silly that u cant link to doc comments
_setupMetricDescriptionToggleListeners() { | ||
const toggle = () => this.metricDescriptionToggleEl.click(); | ||
this.metricDescriptionToggleEl.addEventListener('input', this._toggleMetricDescription); | ||
for (const el of this._dom.findAll('.lh-metric', this._document)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event delegation will be cleaner here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we really only need one click listener, then just make sure the target was an .lh-metric
(though it might as well be on the entire section considering how much of it lh-metric
s take up...I think I agree with @paulirish about the clicking thing)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here's event delegation. and also only using the metric titles as click targets.
this.metricAuditGroup.addEventListener('click', e => {
if (e.target.closest('.lh-metric__title')) this.metricDescriptionToggleEl.click()
});
@@ -81,6 +88,8 @@ class ReportUIFeatures { | |||
this._document.addEventListener('copy', this.onCopy); | |||
this._document.addEventListener('scroll', this._updateStickyHeaderOnScroll); | |||
window.addEventListener('resize', this._updateStickyHeaderOnScroll); | |||
this._setupMetricDescriptionToggleElements(); | |||
this._setupMetricDescriptionToggleListeners(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's just merge these two
@@ -102,6 +103,7 @@ | |||
--env-item-bg: var(--color-black-100); | |||
--env-name-min-width: 220px; | |||
--env-tem-padding: 10px 0px; | |||
--expandable-padding: 0 0 2px 28px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic number here... :/
--score-shape-margin: 7px 12px 0 4px;
--score-shape-size: 12px;
afaik the 28 is 12 + 4 + 12.
I wonder if we can redefine score-shape with some base variable so these remain synchronized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done-ish. shoot, that icon width varies based on the state ...
fill: #7F7F7F; | ||
} | ||
.lh-metrics-toggle input:not(:checked) + label .lh-metrics-toggle-less .lh-metrics-toggle-lines, | ||
.lh-metrics-toggle input:checked + label .lh-metrics-toggle-more .lh-metrics-toggle-lines { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of this, you could override a css var up in the conditional L595 rule ...
--color-lines: var(--color-white);
.lh-metrics-toggle input:checked + label .lh-metrics-toggle-more .lh-metrics-toggle-lines { | ||
fill: white; | ||
} | ||
.lh-metrics-toggle label div.lh-metrics-toggle-less { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could afford to be more BEM-y here
.lh-metrics-toggle__icon
.lh-metrics-toggle__icon--expand
border-radius: 20px; | ||
overflow: hidden; | ||
} | ||
.lh-metrics-toggle label div { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be defined closer to the L605 rules. and BEMy would be .lh-metrics-toggle__icon
opacity: 0; | ||
position: absolute; | ||
top: 0; | ||
width: 74px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of these magic numbers you could just do bottom:0; right: 0; and now its 100% 100%. ;)
also not putting left & top together in a rule? what kind of sadist are you? 😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs some tests 🎉 🎉
@@ -200,6 +200,11 @@ class CategoryRenderer { | |||
descriptionEl.classList.add('lh-audit-group__description'); | |||
auditGroupHeader.appendChild(descriptionEl); | |||
} | |||
if (group.title === 'Metrics') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should move this over to performance-category-renderer.js
. It'll have to do an extra step to re-find the header, but it would be good to keep specialized knowledge of the perf category encapsulated in that file if we can
@@ -157,6 +165,24 @@ class ReportUIFeatures { | |||
this._copyAttempt = false; | |||
} | |||
|
|||
_setupMetricDescriptionToggleElements() { | |||
this.metricDescriptionToggleEl = | |||
/** @type {HTMLInputElement} */ (this._dom.find('.lh-metrics-toggle input', this._document)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will need to guard against when there's no perf category
@@ -60,6 +64,9 @@ class ReportUIFeatures { | |||
this.expandAllDetails = this.expandAllDetails.bind(this); | |||
this._toggleDarkTheme = this._toggleDarkTheme.bind(this); | |||
this._updateStickyHeaderOnScroll = this._updateStickyHeaderOnScroll.bind(this); | |||
this._toggleMetricDescription = this._toggleMetricDescription.bind(this); | |||
this._setupMetricDescriptionToggleElements = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't look like it need to be bound?
@brendankenny added tests. Also tried a tests refactor ( |
/** | ||
* @param {LH.JSON} lhr | ||
*/ | ||
function render(lhr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
render function looks 👍
main issue is that it can be pretty slow, so we want to share rendered reports between tests as much as possible, but that's what you do here, so looks good to me
|
||
assert.equal(reportUIFeatures.json, undefined); | ||
reportUIFeatures.initFeatures(sampleResults); | ||
assert.ok(reportUIFeatures.json); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testing json
was being used as a proxy test for the reportUIFeatures being initialized, otherwise this is just testing the report renderer.
We could definitely do something much better if you want to come up with something to test :) or just restore and we'll think about it another day
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just removing it? Doesn't seem useful now that we have all these other tests checking individual behaviors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just removing it?
seems fine now, yeah
lighthouse-core/test/report/html/renderer/report-ui-features-test.js
Outdated
Show resolved
Hide resolved
@@ -795,6 +855,14 @@ | |||
font-weight: bold; | |||
} | |||
|
|||
/* Pushes the metric description toggle button to the right. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if it's really better down here or up with the toggle stuff
_setupMetricDescriptionToggleListeners() { | ||
const toggle = () => this.metricDescriptionToggleEl.click(); | ||
this.metricDescriptionToggleEl.addEventListener('input', this._toggleMetricDescription); | ||
for (const el of this._dom.findAll('.lh-metric', this._document)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we really only need one click listener, then just make sure the target was an .lh-metric
(though it might as well be on the entire section considering how much of it lh-metric
s take up...I think I agree with @paulirish about the clicking thing)
} | ||
.lh-metrics-toggle__input:not(:checked) + label .lh-metrics-toggle__icon--less .lh-metrics-toggle__lines, | ||
.lh-metrics-toggle__input:checked + label .lh-metrics-toggle__icon--more .lh-metrics-toggle__lines { | ||
--color-metric-toggle-lines: var(--color-white); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now you can move this prop into the L601 rule and delete this L608 rule
.lh-metrics-toggle__input:checked + label .lh-metrics-toggle__icon--more .lh-metrics-toggle__lines { | ||
--color-metric-toggle-lines: var(--color-white); | ||
} | ||
.lh-metrics-toggle label .lh-metrics-toggle__icon--less { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the base .lh-metrics-toggle__icon
rule could assume the --less
case so this rule isnt necessary
regardless you can move width/height into the base lh-metrics-toggle__icon
rule
<defs> | ||
<path id="a" d="M0 0h24v24H0V0z" /> | ||
</defs> | ||
<path class="lh-metrics-toggle__lines" d="M4 9h16v2H4zm0 4h10v2H4z" clip-path="url(#b)" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you can just delete clip-path attribute and the <defs>
above. it seems to be ignored.
…est.js Co-Authored-By: Hoten <[email protected]>
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
…house into report-ui-metric-desc
not crazy about how the tab control is styled, thoughts? |
up to @paulirish on if he likes this :) |
#8185