Skip to content

fix(JumpLinks): Fix aria issues #11950

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Conversation

rebeccaalpert
Copy link
Member

@rebeccaalpert rebeccaalpert commented Aug 1, 2025

What: Remove aria-label from toggle if there is visible text. Add aria-labelled by if there is visible text. Added aria-labels to examples. Made example labels unique.

Closes #11395

Additional issues:

@patternfly-build
Copy link
Contributor

patternfly-build commented Aug 1, 2025

@rebeccaalpert rebeccaalpert marked this pull request as ready for review August 1, 2025 14:42
@rebeccaalpert rebeccaalpert requested review from thatblindgeye, a team and wise-king-sullyman and removed request for a team August 1, 2025 14:42
Remove aria-label from toggle if there is visible text. Add aria-labelled by if there is visible text. Added aria-labels to examples.
Copy link
Contributor

@wise-king-sullyman wise-king-sullyman left a comment

Choose a reason for hiding this comment

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

🔥 double approval

Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

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

Some comments below, also:

  • for the "Expandable vertical with subsection" example, let's add an aria-label or aria-labelledby to the nested JumpLinksList in the example. Personally I'd love if this example used more unique text for each item for a more real-world like example, but I'd be fine just passing in an aria prop to JumpLinksList
  • The "With label" example just needs to have their labels updated as they're both still "Jump to section"

@@ -232,6 +243,11 @@ export const JumpLinks: React.FunctionComponent<JumpLinksProps> = ({
return child;
});

const id = getUniqueId();
const hasAriaLabelledBy = expandable || (label && alwaysShowLabel);
const computedAriaLabel = hasAriaLabelledBy ? null : ariaLabel;
Copy link
Contributor

Choose a reason for hiding this comment

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

This will be fine for now, but in the next breaking change we should tweak some of the logic for the aria in this component. Ideally we should allow both aria-labelledby and aria-label to be passed in (an element having an aria-label then referencing itself + some other element with an aria-labelledby).

Right now if we allowed that it'd cause redundancy by default whenever a label is passed in. #9802 can probably cover such updates especially since that will handle adding an aria-labelledby prop for customization as well.

@rebeccaalpert
Copy link
Member Author

I think I addressed your comments @thatblindgeye but let me know if you want further changes!

Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

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

This is looking nice 😎 Only other thing is adding some tests. JumpLinks hasn't been revamped in its unit tests yet, but for sake of whomever does work on these remaining components it'd be good to help cover some of these new features. Typically what I've done is maybe add a comment in the test file at the end saying something like "Revamped tests begin here" or "Remove tests above here" or something, just some way to separate the old tests we'll most likely remove in a revamp and tests that should remain.

Just a few tests to add in this PR:

  • labelId gets rendered properly on the correct element (when expandable is true and when it isnt)
  • the random id is rendered when labelId is not passed
  • the console warnings are thrown when expected and not thrown when not

the logic for the aria attributes I'll leave up to you if you want to include in tests. Those are mostly pre-existing things so I'd consider that part of the actual revamp of the JumpLinks unit tests.

@rebeccaalpert
Copy link
Member Author

I did half and half @thatblindgeye - added a couple of extra tests, but stuck mostly to the logic added here.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug - JumpLinks - aria attributes need correcting
4 participants