Skip to content
21 changes: 16 additions & 5 deletions src/components/Nav/MainNavLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const MainNavLinks = ({
class={styles.toggle}
onClick={handleToggle}
aria-expanded={isOpen}
aria-controls="main-links-list main-cta-list"
aria-label={mobileMenuLabel || "Toggle navigation menu"}
>
<div class={styles.mobileMenuLabel}>
Expand All @@ -72,24 +73,34 @@ export const MainNavLinks = ({
}`}
>
{renderLogo()}
<ul>
<ul id="main-links-list" hidden={!isOpen}>
{links.map((link) => (
<li key={link.label}>
<a href={link.url}>{link.label}</a>
<a href={link.url} tabIndex={isOpen ? undefined : -1}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can simplify this. Because hidden normally handles focus prevention, we can omit the tabIndex manipulation on each link.

{link.label}
</a>
</li>
))}
</ul>
<ul class="flex flex-col gap-[15px]">
<ul id="main-cta-list" class="flex flex-col gap-[15px]" hidden={!isOpen}>
Copy link
Collaborator

@coseeian coseeian Dec 11, 2025

Choose a reason for hiding this comment

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

Per hidden attribute's HTML spec:

Because this attribute is typically implemented using CSS, it's also possible to override it using CSS. For instance, a rule that applies 'display: block' to all elements will cancel the effects of the Hidden state.

When both hidden and display:flex appears on the same element (plus if we remove the manual tabIndex={isOpen ? undefined : -1} manipulation on each link for code simplicity), the element is still focusable.

To maintain proper compliance with the hidden attribute's intended behavior, I would suggest applying the flex class only when isOpen=true.

ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/hidden#the_hidden_state

<li>
<a className={styles.buttonlink} href="https://editor.p5js.org">
<a
className={styles.buttonlink}
href="https://editor.p5js.org"
tabIndex={isOpen ? undefined : -1}
>
<div class="mr-xxs">
<Icon kind="code-brackets" />
</div>
{editorButtonLabel}
</a>
</li>
<li>
<a className={styles.buttonlink} href="/donate/">
<a
className={styles.buttonlink}
href="/donate/"
tabIndex={isOpen ? undefined : -1}
>
<div class="mr-xxs">
<Icon kind="heart" />
</div>
Expand Down