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

add SkipToContent button to SubdomainNavBar #503

Merged
merged 18 commits into from
Mar 8, 2024

Conversation

joseph-lozano
Copy link
Contributor

@joseph-lozano joseph-lozano commented Nov 22, 2023

Summary

Adds a SkipToContent button to the SubdomainNavBar

List of notable changes:

  • Adds a SkipToContent button to the SubdomainNavBar

What should reviewers focus on?

Does the button work?
Does it properly hide itself when not in focus?
Does it jump to the content of the page.

Steps to test:

You can test this component on any of the SubdomainNavBar stories, e.g. https://primer-6e6587907b-26139705.drafts.github.io/storybook/?path=/story/components-subdomainnavbar--playground

Supporting resources (related issues, external links, etc):

Solves #404

Contributor checklist:

  • All new and existing CI checks pass
  • Tests prove that the feature works and covers both happy and unhappy paths
  • Any drop in coverage, breaking changes or regressions have been documented above
  • New visual snapshots have been generated / updated for any UI changes
  • All developer debugging and non-functional logging has been removed
  • Related issues have been referenced in the PR description

Reviewer checklist:

  • Check that pull request and proposed changes adhere to our contribution guidelines and code of conduct
  • Check that tests prove the feature works and covers both happy and unhappy paths
  • Check that there aren't other open Pull Requests for the same update/change

Screenshots:

Please try to provide before and after screenshots or videos

Before After

CleanShot 2023-11-27 at 08 22 01@2x

CleanShot 2023-11-27 at 08 21 47@2x

Copy link

changeset-bot bot commented Nov 22, 2023

🦋 Changeset detected

Latest commit: 3e86b7d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@primer/react-brand Minor
@primer/brand-primitives Minor
@primer/brand-e2e Minor
@primer/brand-fonts Minor
@primer/brand-config Minor
@primer/brand-storybook Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Nov 22, 2023

🟢 No design token changes found

Copy link
Contributor

github-actions bot commented Nov 22, 2023

⚠️ Visual differences found

Our visual comparison tests found UI differences.

Please review the differences by using the test artifacts to ensure that the changes were intentional.

Artifacts can be downloaded and reviewed locally.

Download links are available at the bottom of the workflow summary screen.

Example:

artifacts section of workflow run

If the changes are expected, please run npm run test:visual:update-snapshots to replace the previous fixtures.

Review visual differences

@joseph-lozano joseph-lozano marked this pull request as ready for review November 22, 2023 21:11
@joseph-lozano joseph-lozano requested a review from rezrah November 22, 2023 21:11
@joseph-lozano joseph-lozano linked an issue Nov 27, 2023 that may be closed by this pull request
@joseph-lozano joseph-lozano self-assigned this Nov 29, 2023
Comment on lines 662 to 667
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip: rect(1px, 1px, 1px, 1px);
border: 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is just visually hiding it, right? If so, could this be done programmatically by adding the global visually-hidden class?

Comment on lines 139 to 151
<Button
as="a"
href="#start-of-content"
variant="primary"
className={clsx(styles['SubdomainNavBar-skip-to-content'])}
>
Skip to content
</Button>
Copy link
Collaborator

Choose a reason for hiding this comment

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

@auareyou Checking that you've seen the proposed design here? I'm not sure the button styling works, and that we need something a bit more custom. The button feels too big IMO. What do you think? Happy to take your steer here.

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Discussed at maintainer sync. We'll move forward with this design as an interim-step, with @auareyou exploring more integrated presentation down the line.

@nsolerieu
Copy link
Contributor

@joseph-lozano I'd suggest use banner stretching under the header to avoid having the button awkwardly overlap the header UI like this:

Screenshot 2023-12-04 at 11 22 49 AM

Since this would be a custom additions we could consider using our button component and stretch it full width (like Linear does). Since our CTA component is very chunky it would look like this - ideally we'd want to remove the border radius for it too look more like the banner above.

Screenshot 2023-12-04 at 11 26 47 AM

Happy to see/review whatever is feasible here

Comment on lines 147 to 148
onFocus={() => setStartOfContentButtonFocused(true)}
onBlur={() => setStartOfContentButtonFocused(false)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Possible to extract these functions outside of the return statement please? Potentially wrapping in a useCallback? Micro-perf optimisation to avoid creating a new function each time. I missed this last time, sorry.

Copy link
Collaborator

@rezrah rezrah left a comment

Choose a reason for hiding this comment

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

LGTM. Added some more minor feedback, otherwise good to go :shipit:

Nice work @joseph-lozano

@joseph-lozano
Copy link
Contributor Author

After chatting at the Accessiblity Eng+ Office Hours, it sounds like we should first look for a <main> element before falling back to creating an empty div for the start-of-content.

Additionally, if we create the start-of-content empty div, we should make sure to give it tabindex="-1".

https://github.com/github/accessibility/issues/5240

@joseph-lozano joseph-lozano marked this pull request as draft December 13, 2023 17:20
@joseph-lozano joseph-lozano force-pushed the joseph-lozano/start-of-content-btn branch from 502d4b6 to 96d963d Compare December 14, 2023 15:46
Comment on lines 93 to 98
useEffect(() => {
const main = document.getElementsByTagName('main')[0] as HTMLElement | undefined
if (!main) return
if (!main.id && startOfContentID) main.id = startOfContentID
setMainTag(main)
}, [setMainTag, startOfContentID])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rezrah this seems... somehow wrong, but unsure how else I might satisfy the a11y team's recommendation. Do you have any thoughts?

Copy link
Collaborator

@rezrah rezrah Dec 14, 2023

Choose a reason for hiding this comment

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

I wouldn't recommend storing the element in React state, if that's what you're asking?That's really heavy and refs are better for this IMO.

This is just pseudocode so you'll need to try it, but can you do something like:

const mainElRef = useRef<HTMLElement | null>(null);

useEffect(() => {
    const main = document.getElementsByTagName('main')[0] as HTMLElement | undefined
    
  if(el and otherStuff) {
    mainElRef.current = el;
  }

}, []);

Copy link
Contributor

@stamat stamat Feb 28, 2024

Choose a reason for hiding this comment

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

@rezrah my man, I think this is GTG ☺️ , except these two testing stories related to this update are giving AXE errors in CI! Would you know why it is failing? My AXE tooling is showing 0 issues even on strict. And running test:axe doesn't work on Codespaces, so I'll have to try this on my local.

Do we even need them?

@stamat stamat marked this pull request as ready for review February 28, 2024 20:17
@stamat stamat self-requested a review February 28, 2024 20:59
@stamat stamat self-assigned this Mar 4, 2024
@stamat
Copy link
Contributor

stamat commented Mar 5, 2024

@rezrah thanks for helping me sort out running the test:axe. It turned out that it was missing a directory so mkdir apps/docs/public/static which was breaking the run of npm run build:prod --workspace=apps/storybook. So adding the empty dir like you said made it run.

But then this wasn't what I needed, what I needed was to get that storybook-static directory. So you helped me by mentioning npx storybook build so I did this:

cd apps/storybook
npm i # which I think doesn't do anything cause node_modules are in the root directory
npx storybook build

This gave me the storybook-static directory with the stories.json that is needed for the packages/e2e/scripts/playwright/axe-clean.spec.ts to run when called by npm run test:axe --workspace=packages/e2e since this was the CI that was failing and since we don't list all of the violations, I couldn't know this before I got this working locally. I offer to try to write the code for listing the violations, shouldn't be that hard ☺️, so we can see directly from the CI what AXE is telling us. 🪓

So I curated the stories.json to run the two stories in question and found out what it was complaining about, which is this 👇

Screenshot 2024-03-05 at 16 03 51

These stories include <main> tags which automatically have the role="main" and AXE doesn't allow us to have any other role for the <main> tag. But also we have a default Storybook div role="main" which was killing our buzz. 👇

Screenshot 2024-03-05 at 16 16 27

I wonder if we can load the desired story independently of the story chooser. I think we should be able to do so. I'll try to update the code. Here is the suggested sketch: #546

But as the instant remedy I added these two stories in question to the ignore list. Since they are just for testing the ability to scroll to <main>.

P.S. The reason I needed to curate the stories.json is because I was getting an AXE violation for this 👇 😆 It's a banner telling us to update storybook. I think loading the stories independently of the chooser will ignore this violation.

Screenshot 2024-03-05 at 15 56 39

@stamat stamat mentioned this pull request Mar 5, 2024
9 tasks
@stamat stamat merged commit 3098b3b into main Mar 8, 2024
16 of 17 checks passed
@stamat stamat deleted the joseph-lozano/start-of-content-btn branch March 8, 2024 11:28
@primer-css primer-css mentioned this pull request Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Accessibility] Add a "Skip To Content" button to SubdomainNavBar
4 participants