Skip to content
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): tooltip for category description #8840

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lighthouse-core/report/html/renderer/category-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,16 @@ class CategoryRenderer {
gaugeContainerEl.appendChild(gaugeEl);

if (category.description) {
const tooltipTmpl =
this.dom.cloneTemplate('#tmpl-lh-gauge-description-tooltip', this.templateContext);
this.dom.find('.lh-gauge__label', tooltipTmpl).textContent = category.title;
const descEl = this.dom.convertMarkdownLinkSnippets(category.description);
this.dom.find('.lh-category-header__description', tmpl).appendChild(descEl);
this.dom.find('.tooltip', tooltipTmpl).appendChild(descEl);

// Swap score gauge's .lh-gauge__label with the tooltip's .lh-gauge__label-wrapper.
const labelEl = this.dom.find('.lh-gauge__label', tmpl);
const labelWrapperEl = this.dom.find('.lh-gauge__label-wrapper', tooltipTmpl);
labelEl.replaceWith(labelWrapperEl);
}

return /** @type {Element} */ (tmpl.firstElementChild);
Expand Down Expand Up @@ -324,8 +332,7 @@ class CategoryRenderer {
*/
renderScoreGauge(category, groupDefinitions) { // eslint-disable-line no-unused-vars
const tmpl = this.dom.cloneTemplate('#tmpl-lh-gauge', this.templateContext);
const wrapper = /** @type {HTMLAnchorElement} */ (this.dom.find('.lh-gauge__wrapper', tmpl));
wrapper.href = `#${category.id}`;
const wrapper = this.dom.find('.lh-gauge__wrapper', tmpl);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of moving this? (this same code is also in pwa-category-renderer)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was suppressing the click event for links in the description. Only the header should be a clickable link, so the href= was moved to where the header gauges are made.

Should have removed the PWA one too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hows that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that didn't work (just linked to top of page instead). Added a new 'disable' class as a quick fix. but maybe a better (but bigger) change could be done?

wrapper.classList.add(`lh-gauge__wrapper--${Util.calculateRating(category.score)}`);

if (Util.isPluginCategory(category.id)) {
Expand Down Expand Up @@ -353,6 +360,7 @@ class CategoryRenderer {
}

this.dom.find('.lh-gauge__label', tmpl).textContent = category.title;

return tmpl;
}

Expand Down
2 changes: 2 additions & 0 deletions lighthouse-core/report/html/renderer/pwa-category-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ class PwaCategoryRenderer extends CategoryRenderer {
}

this.dom.find('.lh-gauge__label', tmpl).textContent = category.title;

wrapper.title = this._getGaugeTooltip(category.auditRefs, groupDefinitions);

return tmpl;
}

Expand Down
3 changes: 3 additions & 0 deletions lighthouse-core/report/html/renderer/report-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ class ReportRenderer {
for (const category of Object.values(report.categories)) {
const renderer = specificCategoryRenderers[category.id] || categoryRenderer;
const categoryGauge = renderer.renderScoreGauge(category, report.categoryGroups || {});
const wrapper = /** @type {HTMLAnchorElement} */
(categoryRenderer.dom.find('.lh-gauge__wrapper', categoryGauge));
wrapper.href = `#${category.id}`;

if (Util.isPluginCategory(category.id)) {
pluginGauges.push(categoryGauge);
Expand Down
43 changes: 38 additions & 5 deletions lighthouse-core/report/html/report-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@
--navitem-hpadding: var(--body-font-size);
--navitem-vpadding: calc(var(--navitem-line-height) / 2);
--lh-score-highlight-bg: hsla(0, 0%, 90%, 0.2);
--lh-score-icon-background-size: 24px;
--lh-group-icon-background-size: var(--lh-score-icon-background-size);
--lh-info-icon-background-size: 20px;
--lh-score-icon-background-size: 24px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just -lh-score-icon-size ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw ur commenting on something i just reordered

i added --lh-info-icon-background-size

could rename stuff after all this tho

--lh-export-icon-size: var(--lh-score-icon-background-size);
--lh-export-icon-color: var(--medium-75-gray);
--lh-score-margin: 12px;
Expand Down Expand Up @@ -173,6 +174,8 @@
--pwa-fast-reliable-color-url: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><g fill-rule="nonzero" fill="none"><circle fill="%230CCE6B" cx="12" cy="12" r="12"/><path d="M12 4.3l6.3 2.8v4.2c0 3.88-2.69 7.52-6.3 8.4-3.61-.88-6.3-4.51-6.3-8.4V7.1L12 4.3zm-.56 12.88l3.3-5.79.04-.08c.05-.1.01-.29-.26-.29h-1.96l.56-3.92h-.56L9.3 12.82c0 .03.07-.12-.03.07-.11.2-.12.37.2.37h1.97l-.56 3.92h.56z" fill="%23FFF"/></g></svg>');
--pwa-installable-color-url: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><g fill-rule="nonzero" fill="none"><circle fill="%230CCE6B" cx="12" cy="12" r="12"/><path d="M12 5a7 7 0 1 0 0 14 7 7 0 0 0 0-14zm3.5 7.7h-2.8v2.8h-1.4v-2.8H8.5v-1.4h2.8V8.5h1.4v2.8h2.8v1.4z" fill="%23FFF"/></g></svg>');
--pwa-optimized-color-url: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><rect fill="%230CCE6B" width="24" height="24" rx="12"/><path d="M5 5h14v14H5z"/><path fill="%23FFF" d="M12 15.07l3.6 2.18-.95-4.1 3.18-2.76-4.2-.36L12 6.17l-1.64 3.86-4.2.36 3.2 2.76-.96 4.1z"/></g></svg>');

--informative-url: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path fill="%23757575" d="M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z"/></svg>');
}

.lh-vars.dark {
Expand Down Expand Up @@ -1139,6 +1142,16 @@
will-change: opacity; /* Only using for layer promotion */
}

/* Category header gauges shouldn't be links. */
.lh-category-wrapper .lh-gauge__wrapper {
pointer-events: none;
cursor: default;
}
.lh-gauge__label-info-icon {
pointer-events: fill;
cursor: help;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels a tad odd to me to flip the cursor since there's no actual click action here, is there a broader UX strategy here? I would love to learn more about these kinds of things :)

Copy link
Collaborator Author

@connorjclark connorjclark May 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly, I had the bring the cursor back with CSS so I just picked one. Since there's no click action to prompt perhaps it should just remain a normal cursor. IDK.

@yuinchien what do you think of this?
https://lighthouse-33lan68g9.now.sh/#accessibility (hover over i)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hoten I suggest shifting the position 4px downward and to the right.

I applied transform: translate3d(4px,4px,0) to the info icon and it looks like this.

Screen Shot 2019-05-30 at 10 22 10 AM

}

.lh-gauge__label {
font-size: var(--score-title-font-size);
line-height: var(--score-title-line-height);
Expand All @@ -1151,9 +1164,31 @@
.lh-category .lh-gauge__label {
--score-title-font-size: var(--score-title-font-size-big);
--score-title-line-height: var(--score-title-line-height-big);
display: flex;
margin-top: 14px;
}

.lh-gauge__label-wrapper {
position: relative;
color: var(--body-text-color);
}
.lh-gauge__label-wrapper .tooltip-boundary {
display: flex;
position: absolute;
right: calc(-1 * var(--lh-info-icon-background-size));
top: 14px;
}
.lh-gauge__label-wrapper .lh-gauge__label-info-icon {
background-image: var(--informative-url);
background-size: contain;
width: var(--lh-info-icon-background-size);
height: var(--lh-info-icon-background-size);
}
.lh-gauge__label-wrapper .tooltip {
font-size: var(--caption-font-size);
line-height: var(--caption-line-height);
}


.lh-scores-header .lh-gauge__wrapper,
.lh-scores-header .lh-gauge--pwa__wrapper,
Expand Down Expand Up @@ -1246,7 +1281,6 @@
}

.lh-category-header .lh-score__gauge {
max-width: 400px;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just unnecessary or do we want the gauges to get bigger than this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary

width: auto;
margin: 0px auto;
}
Expand Down Expand Up @@ -1445,7 +1479,7 @@
position: absolute;
display: none; /* Don't retain these layers when not needed */
opacity: 0;
background: #ffffff;
background: var(--body-background-color);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

min-width: 246px;
max-width: 275px;
padding: 15px;
Expand All @@ -1470,7 +1504,6 @@
display: block;
animation: fadeInTooltip 250ms;
animation-fill-mode: forwards;
animation-delay: 850ms;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this removes this everywhere, we want that right? I would guess so because a lot of folks don't seem to know that they can hover over the error to get the tooltip 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I figured it doesn't make sense to inject 850ms of latency for this.

bottom: 100%;
z-index: 1;
will-change: opacity;
Expand All @@ -1481,7 +1514,7 @@
.tooltip::before {
content: "";
border: solid transparent;
border-bottom-color: #fff;
border-bottom-color: var(--body-background-color);
border-width: 10px;
position: absolute;
bottom: -20px;
Expand Down
15 changes: 13 additions & 2 deletions lighthouse-core/report/html/templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
<template id="tmpl-lh-category-header">
<div class="lh-category-header">
<div class="lh-score__gauge"></div>
<div class="lh-category-header__description"></div>
</div>
</template>

Expand Down Expand Up @@ -553,6 +552,17 @@
</a>
</template>

<!-- Lighthouse score gauge description tooltip -->
<template id="tmpl-lh-gauge-description-tooltip">
<div class="lh-gauge__label-wrapper">
<!-- TODO: should likely be an h2 -->
<div class="lh-gauge__label"></div>
<span class="tooltip-boundary">
<div class="lh-gauge__label-info-icon"></div>
<div class="lh-category-header__description tooltip"></div>
</span>
</div>
</template>

<!-- Lighthouse PWA badge gauge -->
<template id="tmpl-lh-gauge--pwa">
Expand Down Expand Up @@ -610,7 +620,7 @@
}
</style>

<a href="#" class="lh-gauge__wrapper lh-gauge--pwa__wrapper">
<a class="lh-gauge__wrapper lh-gauge--pwa__wrapper">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 60" class="lh-gauge lh-gauge--pwa">
<defs>
<linearGradient id="lh-gauge--pwa__check-circle__gradient" x1="50%" y1="0%" x2="50%" y2="100%">
Expand Down Expand Up @@ -680,6 +690,7 @@
</g>
</svg>

<!-- TODO: should likely be an h2 -->
<div class="lh-gauge__label"></div>
</a>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe('CategoryRenderer', () => {
const categoryDOM = renderer.render(category, sampleResults.categoryGroups);
assert.ok(categoryDOM.querySelector('.lh-gauge__wrapper--plugin'));
const label = categoryDOM.querySelector('.lh-gauge__label').textContent;
assert.equal(category.title, label);
assert.equal(label, category.title);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was backwards

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was backwards

just for code correctness purposes, not a functional change in the test, I hope?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

});

it('handles markdown in category descriptions a category', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe('PwaCategoryRenderer', () => {
describe('#renderScoreGauge', () => {
it('renders an error score gauge in case of category error', () => {
category.score = null;
const badgeGauge = pwaRenderer.renderScoreGauge(category);
const badgeGauge = pwaRenderer.renderScoreGauge(category, null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of this one? typedef suggests both are unexpected but looking through the code it looks like we never used groups for the score gauge no matter what.... 🤷‍♂

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't recall, removed.


// Not a PWA gauge.
assert.strictEqual(badgeGauge.querySelector('.lh-gauge--pwa__wrapper'), null);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
},
{
"path": "./dist/viewer/src/viewer.js",
"threshold": "70 Kb"
"threshold": "75 Kb"
}
],
"nyc": {
Expand Down