-
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
core(report): show nodeLabel for DOM nodes in addition to snippet #8961
Conversation
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.
nice! Definitely helps give context better than the snippet alone. I wonder if there's more we could do to tie the new text and the snippet together visually, though
@@ -213,6 +214,7 @@ module.exports = [ | |||
'\n big enough target\n </a>', | |||
'path': '2,HTML,1,BODY,3,DIV,21,DIV,1,A', | |||
'selector': 'body > div > div > a', |
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.
can you add to the a11y
expectations as well?
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.
Right now all we assert there is { length: 1 }
, but I'll change it when I do the final artifact update for this PR.
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.
Added details.items
assertions.
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.
Right now all we assert there is { length: 1 }, but I'll change it when I do the final artifact update for this PR.
haha, uh oh, I guess I didn't know how much I was asking for :) I guess we can just cross our fingers that these are stable and all worth testing. I do really like the extra coverage this gets us
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.
When @mattzeunert does something, he does it right, and you get the works! 😎
Removed some unnecessary margin between the two. Not sure what else to do exactly, @hwikyounglee any suggestions? |
Thanks Matt. Only thing I would double check is the contrast of the green text on gray and on white. We need to aim for 4.5 at minimum. @yuinchien for any further guidance |
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 looks great. Last nits
@@ -213,6 +214,7 @@ module.exports = [ | |||
'\n big enough target\n </a>', | |||
'path': '2,HTML,1,BODY,3,DIV,21,DIV,1,A', | |||
'selector': 'body > div > div > a', |
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.
Right now all we assert there is { length: 1 }, but I'll change it when I do the final artifact update for this PR.
haha, uh oh, I guess I didn't know how much I was asking for :) I guess we can just cross our fingers that these are stable and all worth testing. I do really like the extra coverage this gets us
function getNodeLabel(node) { | ||
const tagName = node.tagName.toLowerCase(); | ||
if (tagName !== 'html' && tagName !== 'body') { | ||
const title = node.innerText || node.getAttribute('alt') || node.getAttribute('aria-label'); |
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 a big deal, but I guess s/title/label
function getNodeLabel(node) { | ||
const tagName = node.tagName.toLowerCase(); | ||
if (tagName !== 'html' && tagName !== 'body') { | ||
const title = node.innerText || node.getAttribute('alt') || node.getAttribute('aria-label'); |
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.
also should use the standard node.textContent
(unless innerText
was intentional?)
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 specifically requested innerText because textContent
gets us all that inline script instead of actual text
@@ -352,15 +352,24 @@ class DetailsRenderer { | |||
*/ | |||
renderNode(item) { | |||
const element = this._dom.createElement('span', 'lh-node'); | |||
if (item.nodeLabel) { | |||
const titleEl = this._dom.createElement('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.
labelEl
, etc
@@ -218,6 +218,40 @@ function getNodeSelector(node) { | |||
return parts.join(' > '); | |||
} | |||
|
|||
/** |
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.
can you add a comment for this function? Basically trying to provide a human recognizable label for the given element. Falls back to the tagName if no useful label is found.
/* istanbul ignore next */ | ||
function getNodeLabel(node) { | ||
const tagName = node.tagName.toLowerCase(); | ||
if (tagName !== 'html' && tagName !== 'body') { |
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.
can you add back that comment about why we skip html and body
if (title) { | ||
return truncate(title, 80); | ||
} else { | ||
const nodeToUseForTitle = node.querySelector('[alt], [aria-label]'); |
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.
maybe add comment about why it's useful to recursively search (what cases does this help with?)
@@ -100,6 +100,8 @@ | |||
--color-white: #FFFFFF; | |||
--color-blue-200: #90CAF9; | |||
--color-blue-900: #0D47A1; | |||
--color-teal-300: #00d6c1; | |||
--color-teal-700: #008577; |
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.
Re-introduced teal since it was a bit nicer than the green. Do the numbers at the end have a specific meaning, other than broadly identifying darkness?
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.
It's the shade in the material design color palette https://material.io/design/color/#
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.
is this the right number, then?
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.
LGTM!
@patrickhulce do you want to take another look?
@@ -100,6 +100,8 @@ | |||
--color-white: #FFFFFF; | |||
--color-blue-200: #90CAF9; | |||
--color-blue-900: #0D47A1; | |||
--color-teal-300: #00d6c1; | |||
--color-teal-700: #008577; |
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.
is this the right number, then?
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 don't love the truncate situation, but I won't block an otherwise approved merge because of it either.
I'll just pick "Comment" instead :)
LGTM otherwise!
@@ -213,6 +214,7 @@ module.exports = [ | |||
'\n big enough target\n </a>', | |||
'path': '2,HTML,1,BODY,3,DIV,21,DIV,1,A', | |||
'selector': 'body > div > div > a', |
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.
When @mattzeunert does something, he does it right, and you get the works! 😎
if (tagName !== 'html' && tagName !== 'body') { | ||
const nodeLabel = node.innerText || node.getAttribute('alt') || node.getAttribute('aria-label'); | ||
if (nodeLabel) { | ||
return truncate(nodeLabel, 80); |
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 was making this comment over in #8979 , but it's unfortunate when page-functions in a lib have dependencies on each other that you have to know about ahead of time.
since it's basically a single ternary line WDYT about copying the function definition in the two files instead?
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.
Are you thinking have it in tap-targets.js
and also inlined inside getNodeLabel
?
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.
Yeah that was my thought
@@ -175,6 +178,7 @@ | |||
.lh-vars.dark { | |||
--color-red-700: var(--color-red); | |||
--color-green-700: var(--color-green); | |||
--color-teal-600: var(--color-cyan-500); |
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.
dark mode is weird o.O
with this, tap-targets, iframeelements, and...other stuff(?) making changes to |
Maybe the exported |
…d a new element at the top of the page
Yeah that's a good idea, though perhaps dupes might be an issue then? Since the function is so simple here I think inline is decent option, but we'll have to figure this out long-term for sure either. |
Is there an issue with dupes other than aesthetics? There'd be a perf impact but that seems very minor. |
I was thinking of variable declarations not function declarations, but I suppose all our dupes would be of function declarations, so it's a non-issue. 👍 |
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.
LGTM! Thanks @mattzeunert for the fix! 🙏
Summary
Collect a human-readable title for each node and display it above the snippet.
Related Issues/PRs
#6683