-
Notifications
You must be signed in to change notification settings - Fork 471
What do we recommend people do for elements that have no implicit role (like input[type=password]) #567
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
Comments
Interesting discussion on the reason passwords don't have a role: w3c/aria#935 |
I think this is our safest bet. I wouldn't want to diverge from the spec. Otherwise people might use If people stumble over this often when doing |
Quite conveniently (or not), I've just faced this issue and was confused as to why my password input just couldn't be found. Using
I'd appreciate eps1lon's suggestion, but if this would result in some hacky, unstable solution I'd rather stick with what I already have. |
I would suggest to use |
Thanks for the input @weyert. You actually get the exact same benefit (and more) by using The issues is brought up because password fields don't have an implicit role assigned to them like regular inputs, so (as @Tohaker pointed out) it looks a little odd. I'm pretty sure this is what we'll recommend however, so I'll go ahead and close this. |
Disclaimer: Speculation & My Opinion |
Password fields aren't encrypted, so they have pretty much no security in the client. What matters is that they have secure transport over the network (like a secure API using HTTPS). |
You can just add the attribute role="textbox" to your Input, and then find it by: |
Setting roles manually is not advisable without testing how assistive technologies behave when you do. When in doubt, follow the spec. |
Thanks Kent! I took into account your comment, so I modified it by adding aria-label="password" and then I could find it by getByLabel('password'). I was not using Label and Input, it was a Form.Input, do you have any suggestions about this approach or do you think this way is better? |
The first rule of aria is "don't use aria" 😅 It's much better for accessibility to use an actual |
I thought that aria-label could be used when you don't have a label text visible on the screen, and it was the case since I was trying to get the Input within a Form without having a label element available, but, on the other hand, I do have a placeholder defined, so thinking in what you're saying, I could use that instead of adding more attributes. |
input[type=password]의 경우 role을 가지고있지 않음 테스트할 때는 getByLabelText를 권장한다. 관련 토론: - 암호에 role이 없는 이유애 대한 토론 내용도 나온다. testing-library/dom-testing-library#567
Password fields do not have a role and so have to be selected with *ByLabelText instead of *ByRole. See testing-library/dom-testing-library#567 for more info.
Say you have a login form:
You can retrieve the username field via:
screen.getByRole('textbox', {name: /username/i})
However, the password field has no implicit role so you'd have to usegetByLabelText(/password/i)
for that one.I'm guessing that we just recommend people use
getByLabelText
as a fallback in this case, but I'm curious what other people think about this (especially curious to hear @eps1lon's thoughts here).The text was updated successfully, but these errors were encountered: