Skip to content

aria-label or test-id for for elements with no role ? #1151

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

Closed
mo-alaa opened this issue Jul 23, 2022 · 4 comments
Closed

aria-label or test-id for for elements with no role ? #1151

mo-alaa opened this issue Jul 23, 2022 · 4 comments

Comments

@mo-alaa
Copy link

mo-alaa commented Jul 23, 2022

Hi, I have a hidden input inside a button to upload files.

<button>
  <p>upload</p>
  <input hidden type='file'/>
</button>

since the input 'file' doesn't have a role by default, should I add an "aria-label" or a
"data-testid" for the input element?

Because as said here : 'The first rule of aria is don't use aria'.

Also testing library says this about using data-testid : 'Using data-testid attributes do not resemble how your software is used and should be avoided if possible'

so what should I pick ?

@eps1lon
Copy link
Member

eps1lon commented Jul 24, 2022

How is the hidden input used? If it's in a form whose data you use, test submitting it and check for data.

It's generally hard to give good advise without knowing the full UI.

@alexkrolick
Copy link
Collaborator

since the input 'file' doesn't have a role by default

the default role of a file input is button

image

@MatanBobi
Copy link
Member

@alexkrolick that's probably a chrome decision and not a spec definition so I guess it might not work in JSDOM.
Based on the spec, as @mo-alaa said, input type file has no implicit role:
image

@eps1lon
Copy link
Member

eps1lon commented Jul 27, 2022

Closing in favor of https://testing-library.com/discord. The documentation still applies. But concrete advise depends on the actual UI.

@eps1lon eps1lon closed this as not planned Won't fix, can't repro, duplicate, stale Jul 27, 2022
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

No branches or pull requests

4 participants