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

init: add skip-to-main-content shortcut #7390

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

yaten2302
Copy link

Description

This PR adds a skip to main content button (initially hidden), when the user presses Tab(for windows), the button is visible and the user can then move directly to the main content of the page.

Related Issues

Fixes #7220

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run npm run format to ensure the code follows the style guide.
  • I have run npm run test to check if all tests are passing.
  • I have run npx turbo build to check if the website builds without errors.
  • I've covered new added functionality with unit tests if necessary.

@yaten2302 yaten2302 requested a review from a team as a code owner January 7, 2025 06:57
Copy link

vercel bot commented Jan 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nodejs-org ✅ Ready (Inspect) Visit Preview Jan 16, 2025 5:45pm

@yaten2302
Copy link
Author

yaten2302 commented Jan 7, 2025

I think currently on pressing Tab, the button is shown, but it's not getting pressed if the user presses Enter, I forgot take into account the Enter button, I'll push a commit for this too 👍

Edit: Sorry, will not ping 👍

@AugustinMauroy
Copy link
Member

WOW stop pinging everyone ! we (website team) receive notification when there are changes on repo.

apps/site/components/withNavBar.tsx Show resolved Hide resolved
apps/site/components/withNavBar.tsx Outdated Show resolved Hide resolved
apps/site/components/withNavBar.tsx Outdated Show resolved Hide resolved
Signed-off-by: Yaten Dhingra <[email protected]>
Signed-off-by: Yaten Dhingra <[email protected]>
Comment on lines 33 to 37
const handleTabPress = (event: KeyboardEvent<HTMLInputElement>) => {
if (event.key === 'Tab') {
setTabPressed(prev => !prev);
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

That's very wrong, we should not rely on keyboard event, it's arbitrary restrictive. In fact we shouldn't be using JS at all, there's no reason this couldn't be CSS-only

Copy link
Author

Choose a reason for hiding this comment

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

Got your point, I'll make it CSS-only and remove all the JS 👍

Copy link
Author

Choose a reason for hiding this comment

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

I've made the change CSS-only, but I've a doubt that what should be the bg-color of the button? I wasn't able to find it in the component. Currently I've set it to black, for testing purposes only!!

Copy link
Member

Choose a reason for hiding this comment

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

we already have a button component

Copy link
Author

Choose a reason for hiding this comment

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

Yes, there's a button component present, but the issue with that is - empty space is being left on using it, like this:

image

Should I try to resolve this with CSS or it can easily be fixed by using <a> tag and then simply adding the bg-color, so how should I go?


const toggleCurrentTheme = () =>
setTheme(resolvedTheme === 'dark' ? 'light' : 'dark');

return (
<div>
<a className={classNameOnTabPress} href="#main">
Copy link
Member

Choose a reason for hiding this comment

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

Anchor href is not working, main element is missing the id attribute.

Copy link
Author

Choose a reason for hiding this comment

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

This href won't work as of now, because I just set it randomly to #main, I wanted to clarify that to what section the user must be directed to on clicking this button?

Copy link
Member

Choose a reason for hiding this comment

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

I believe It should redirect to main indeed

Copy link
Author

Choose a reason for hiding this comment

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

For this, is there a main class present in the pages? Ig not?
There is this <main/> tag present in the about page, just for example.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I don't understand what you saying

Copy link
Author

Choose a reason for hiding this comment

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

I was trying to say that on any page, since we're redirecting to #main, there is no such class as #main on any page, so where should the user be redirected?

@@ -16,13 +17,23 @@ const WithNavBar: FC = () => {
const { replace } = useRouter();
const pathname = usePathname();

const classNameOnTabPress = classNames(
Copy link
Member

Choose a reason for hiding this comment

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

I believe that creating a SkipToContentButton component would make this cleaner.

Copy link
Member

Choose a reason for hiding this comment

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

And I feel that WithLayout is a better place to put this component.

Copy link
Author

Choose a reason for hiding this comment

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

Should I change classNameOnTabPress to SkipToContentButton?

Copy link
Author

Choose a reason for hiding this comment

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

And I feel that WithLayout is a better place to put this component.

All these changes have to be shifted to the withLayout, am I right?

Copy link
Member

Choose a reason for hiding this comment

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

Should I change classNameOnTabPress to SkipToContentButton?

Yes

And I feel that WithLayout is a better place to put this component.

All these changes have to be shifted to the withLayout, am I right?

Yep

Copy link
Author

Choose a reason for hiding this comment

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

If I've understood this correct, then should I add a new skipToContent in here?

Copy link
Author

Choose a reason for hiding this comment

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

Hey, apologies for delay!
I've pushed a commit to address this, could you please have a look at it?
Thanks

@yaten2302
Copy link
Author

I've pushed a minor change(typo). Just wanted to ask, that could anyone please guide regarding these points, I was having a few doubts:

  1. What should be the bg color?
  2. init: add skip-to-main-content shortcut #7390 (comment)

@yaten2302
Copy link
Author

Hi, I've pushed a commit, and I think that this addresses all the changes mentioned and required! Could anyone please have a look at it and LMK if any change has to be made in this?

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.

Adding a "Skip to Content" Link
5 participants