-
Notifications
You must be signed in to change notification settings - Fork 152
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
refactor: replacing div with role=heading with native heading element issue #5120 #5189
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.
Thanks for opening this PR! I believe these 4 headings cover the scope of the bug, and your changes look on the right track to me!
One thing to keep in mind: the switch to elements has some minor styling impacts around spacing and font. For example, here is Launch pad heading change before the h2 change:
and after the change, now with some minor spacing differences:
We probably need to introduce a few css tweaks to make sure the new headings look like the old ones 🙂
@@ -26,7 +27,10 @@ const ReportCollapsibleContainer = NamedFC<ReportCollapsibleContainerProps>( | |||
|
|||
return ( | |||
<div className={outerDivClassName}> | |||
<div className="title-container" role="heading" aria-level={headingLevel}> | |||
<HeadingElementForLevel | |||
headingLevel={headingLevel as HeadingLevel} |
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.
Rather than using a type assertion here, it might be better to update the type of headingLevel
in ReportCollapsibleContainerProps
to be HeadingLevel
. I believe there are a few other places in our props where headingLevel: number
would make more sense as headingLevel: HeadingLevel
with this change, 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.
@jalkire thanks a lot for looking at this!
You are right I overlooked the css change, sorry about that. COuld you guide me to the use of the report-collapsible-container? I am not 100% sure I am looking at the right element. For the issue you pointed out, I believe I found a solution for the issue, I have added a new commit.
I can see that there is also an issue with the styling of the heading in how-to-test, it used to not be styled as a heading and now has the heading styling. I just want to verrify that this is really how it is supposed to be (since I am completly new here)?
old:
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.
@jalkire one more question, the snapshot test src/tests/unit/tests/reports/components/report-sections/report-collapsible-container.test.tsx:35:45 is failing as it is expecing 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.
Great, thank you for those updates! To your questions:
- For the use of report-collapsible-container, we use that in the html reports that the extension exports. The easiest way to see it is by clicking "Export result" from a FastPass in the extension--the parts of the downloaded html report that expand/collapse on click are in the
ReportCollapsibleContainer
. - For the snapshots, if you add
-u
after the test command that will update the snapshots. Then you can confirm that the changes make sense 🙂 - For the tab stops how to test heading, I would default to leaving it as-is, but tagging @ferBonnin in case the heading style should be changed.
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.
thanks for this contributions @majaokholm! For the Tab stops How to test Heading, I recommend we have it as an H2, so its the same as the why it matters headings 🙂
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.
@jalkire Thanks again for the feedback! But I am afraid I need to ask for a bit of help once more; to fix the last styling differences I need to update css for the report-collapsible-container (because the default browser styling for h4 elements is being applied now), but I can’t figure out which components uses which stylesheet, or how to add a new one. It should be so simple but I spend so much time trying to resolve this that I figured out it is time to ask for help. Can you please guide me once more? Thanks again!
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.
Sure thing! Unfortunately this particular styling looks a little messy on our end--tab-stops-failed-instance-section.scss, result-section.scss, automated-checks-report.scss, and collapsible-url-result-section.scss all set properties on title-container in report-collapsible-container.tsx. I might be missing something myself, but you're probably best off applying your fix to all of those.
This somewhat relates to the last failing PR check, e2e-report-tests--once you get that css updated, you can get the test passing by running yarn build:package:report
and then yarn test:report:e2e -- -- -- -u
to update report snapshots.
Thanks for putting in all this effort, you're almost there!
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 found a way to make it work (I believe) but am not convinced it's the most elegant solution.
From my understanding, the title-container styling in the files you refered (tab-stops-failed-instance-section.scss, result-section.scss, automated-checks-report.scss, and collapsible-url-result-section.scss) are not applied in the case of the report-collapsible-container.tsx as the title-container styling is nested inside other classes in all the cases and neither of these classes are applied in the report-collapsible-container.tsx case. So I ended up appling the change to the content.scss file, which seems to work, but maybe a new file would have been better?
And thanks for the guidance - again, again :-)
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.
Thank you for taking a look at that! With the content.scss changes, I'm still seeing the default margin-block
values causing extra spacing to appear in the fastpass report:
In the old report, the h3 and h4 labelled elements (lowercase h indicating that these aren't native H elements) are stacked with no extra spacing. In the updated report, those are now proper H3 and H4 elements, but there's now some extra spacing.
Instead of putting the change in content.scss or the my other previous suggestions, I was able to get things looking right by adding your css changes to results-container.scss, something like:
.results-container {
margin-top: 56px;
.title-container {
font-weight: unset;
margin-block: 0;
margin-inline: 0;
}
}
@@ -115,7 +115,7 @@ html { | |||
-moz-box-sizing: border-box; | |||
} | |||
|
|||
#popup-container [role='heading'] { | |||
#popup-container :is(h1, h2, h3, h4, h5, h6) { | |||
width: fit-content; | |||
padding-left: 0; | |||
} |
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 newly updated popup heading could use a margin-block: 0;
to remove some extra spacing🙂
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.
Thanks a lot for the suggestions, I have implemented both however the e2e report is still failing when I run it locally. I am struggeling to find the source of the issue, and in my digging I found another '<div role=heading' element being used in the rule-details-group in the DetailsView which I believe comes from the rules-with-instance.tsx component. However I am not sure how to change this to a native element. This also doesn't make sense as the source of the failing tests as this file hasn't been changed for a long time. So long story short, I am a bit lost again, but will have a look again tomorrow -hopefully with fresh eyes
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.
Thank you for looking into that! For the report e2e test, I'm still able to get that working with yarn build:package:report
and then yarn test:report:e2e -- -- -- -u
, and the snapshot updates look reasonable to me.
For the remaining role=heading div
, now that you mention it, I'm seeing a few other role=heading based headings that were a bit trickier to find in the code. Sorry for not finding those earlier! I've found one with the props defined elsewhere (probably the one you're seeing that gets headingLevel from rules-with-instance.tsx), and then a few using span
rather than div
: 1, 2, 3.
Given how much you've already put into this already, it would be totally fair to wrap up this PR without adding any of those, or just addressing that last div
heading. Whatever you'd like to do!
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 am looking into it and will get back - not sure if I will be able to fix it all so might make sense to scope some out but will have a closer look first
@jalkire is there a way to run the web-e2e-reliability test locally? |
That just runs the normal e2e tests repeatedly via |
I am afraid I will not be able to get any further with this. I fixed the collapsible-component-cards.tsx but I am still think there are a few more somewhere that are better hidden, but I have not been able to get further. |
Thanks for getting that component fixed up! The issues with the e2e-reliability tests are not actually related to your changes, so you should be good to go 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.
Thank you for all the time that you put into this contribution!
Thank you for all the help @jalkire :-) |
Details
Refactoring the codebase to use native heading elements instead of div elements with role = heading as per issue #5120
Motivation
addresses issue #5120
Context
I replaced previously hardcoded levels with the corosponding h element directly and the previously dynamic levels with the element HeadingElementForLevel as this elemnt seems to serve the purpose of dynamically creating a native h-element of a given level.
I intentionally left out the tests (both e2e and unit) as I am not certain what the correct action is here.
Pull request checklist
yarn fastpass
yarn test
)<rootDir>/test-results/unit/coverage
fix:
,chore:
,feat(feature-name):
,refactor:
). SeeCONTRIBUTING.md
.