Skip to content

[BUG] - Accessible label for Input component is duplicated #5150

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

Open
dklymenk opened this issue Apr 4, 2025 · 5 comments · May be fixed by #5161
Open

[BUG] - Accessible label for Input component is duplicated #5150

dklymenk opened this issue Apr 4, 2025 · 5 comments · May be fixed by #5161
Labels
♿ Scope : Accessibility Related to accessibility

Comments

@dklymenk
Copy link

dklymenk commented Apr 4, 2025

HeroUI Version

2.7.5

Describe the bug

The accessible label for <Input label="Email" /> resolves as "Email Email".

Your Example Website or App

https://www.heroui.com/docs/components/input#usage

Steps to Reproduce the Bug or Issue

  1. Navigate to https://www.heroui.com/docs/components/input#usage.
    2.1. Using your browser's dev tools, inspect the accessible label of one of the inputs.
    2.2. Using the screen reader, read out the label of one of the inputs.

Expected behavior

As a user, I don't expect the label to be duplicated when interacting with the element when using assistive technologies.

Screenshots or Videos

Firefox dev tools:
Image
Voiceover:
Image

Operating System Version

macOS

Browser

Firefox

Copy link

linear bot commented Apr 4, 2025

@dklymenk
Copy link
Author

dklymenk commented Apr 4, 2025

This issue originally came up when I was trying to select the input with a getByLabelText selector from react-testing-library.

I have identified that the input is rendered with aria-labelledby="react-aria-:r13: react-aria-:r14:". react-aria-:r13: points to the input element itself and react-aria-:r14: points to the label. The browsers, following the standard, then concatenate the two labels and expose the result to accessibility tree.

@dklymenk
Copy link
Author

dklymenk commented Apr 4, 2025

I found that if "aria-label" key is not passed to useTextField from @react-aria/textfield, the duplication does not occur.

I believe that passing both label and aria-label to react-aria results in both somehow being represented in aria-labelledby.

There is this part of useLabel in react-aria that does some sort of concatenation https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/label/src/useLabel.ts#L50. It doesn't even look like the exact concatenation that I've reported, but the tests for the hook assert the concatenation of label and aria-label.

@dklymenk
Copy link
Author

dklymenk commented Apr 4, 2025

Ok, I figured it out.

useLabel generates labelId and assigns it to ariaLabelledby.
https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/label/src/useLabel.ts#L50

The object with ariaLabelledby is passed to useLabels.
https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/label/src/useLabel.ts#L59-L63

Both element's id and ariaLabelledby are concatenated in useLabels.
https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/utils/src/useLabels.ts#L31-L33

It seems wrong even though the tests indicate that this behaviour is intentional.

I'll create an issue there at react-spectrum to get clarification on whether this is indeed intentional.

@dklymenk
Copy link
Author

dklymenk commented Apr 5, 2025

Started a discussion on the react-spectrum repo to get some clarity on the matter.
adobe/react-spectrum#8037

@wingkwong wingkwong added the ♿ Scope : Accessibility Related to accessibility label Apr 6, 2025
@dklymenk dklymenk linked a pull request Apr 7, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
♿ Scope : Accessibility Related to accessibility
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants