Skip to content

Conversation

@kettanaito
Copy link
Member

@kettanaito kettanaito commented Aug 25, 2025

When testing the Epic Stack app as a part of my recent workshop, I've noticed that certain UI elements have poor accessibility, which resulted in them being rather difficult to properly target during the tests.

The user menu dropdown is one such example. Right now, it has an accessible name comprised of the username repeated twice:

Screenshot 2025-08-25 at 11 24 18

This happens because the dropdown has two elements, each of which has user's username as the accessible text:

  • the avatar img as alt={user.name}
  • the dropdown button content is user.name.

That results into the element's accessible name being "Kody Kody", which looks broken, especially if you want to target this user dropdown in tests.

Instead, the element's accessible text should describe what that element is or does. In this case, I propose it should be something like "User menu".

There's a similar problem for the search results:

Screenshot 2025-08-25 at 12 03 06

"Kody Kody Kody" isn't a very nice accessible name that describes what that link is/does. I propose {user.name || user.username} profile instead because that's what happens when you click on that link—it brings you to that user's profile page.

Test Plan

Checklist

  • Tests updated
  • Docs updated

Screenshots

Why wasn't this caught in tests?

Because the current tests target this element by inclusive name, not exact name:

await page.getByRole('link', { name: user.name ?? user.username }).click()

Saying { name: 'Kody' } will match Kody Kody without ever surfacing that the element's accessible name is problematic. This is a +1 for using exact: true as the default.

src={getUserImgSrc(user.image?.objectKey)}
width={256}
height={256}
aria-hidden="true"
Copy link
Member Author

Choose a reason for hiding this comment

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

The user avatar is a decorative element in this context and should be disregarded accessibility-wise. Even its alt is not needed, but I fear to anger eslint at this point.

// this is for progressive enhancement
onClick={(e) => e.preventDefault()}
className="flex items-center gap-2"
aria-label="User menu"
Copy link
Member Author

Choose a reason for hiding this comment

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

Using an explicit label will override whatever accessible text the element has inferred.

@kettanaito kettanaito changed the title fix: improve accessibility of the user menu fix: improve accessibility of UI elements Aug 25, 2025
@kettanaito kettanaito force-pushed the fix/user-menu-accessibility branch from 4f35c1d to 3cfca58 Compare August 25, 2025 10:04
@kettanaito kettanaito requested a review from kentcdodds August 25, 2025 10:12
Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Yes, this is definitely better. Thanks!

@kentcdodds kentcdodds merged commit 33d6193 into main Aug 25, 2025
6 checks passed
@kentcdodds kentcdodds deleted the fix/user-menu-accessibility branch August 25, 2025 17:51
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.

3 participants