-
Notifications
You must be signed in to change notification settings - Fork 401
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
add aria-disabled in the toBeDisabled
matcher
#144
Comments
tobedisabled
matcher
I wasn't aware of this issue so I want to summarize some concerns that I raised when the implementation was proposed: The
So while I do see the usefulness of an |
@eps1lon thanks for the input, i suppose i was thinking (maybe incorrectly) that this would be inline with the testing-library philosophy, that tests shouldn't necessary be testing implementation details (which exact attributes has a value) but should be testing what a user observes as the behaviour. for the latter case, to a screenreader client however for my own self interest, would there be a better way to indicate disabled SVG buttons/Clickable elements that would be testable using |
Partially. But you're not matching So to summarize:
If you want that Also want to address
checking that a disabled element is not focusable is not an implementation detail. This is very much observable both by users with and without assistive technology. |
So to summarize, @eps1lon, what you're proposing is that we leave |
@gnapse 👍 That seems like it would adress the original issue and be safe for UX testing. |
If
It doesn't look like I think it makes more sense to add the |
Yep although I would make sure there aren't other libraries out there that already reflect aria properties.
If |
It does feel like Also wouldn't the user of https://www.w3.org/TR/wai-aria-1.1/#aria-disabled
|
Yes. I can't stress this enough: Using aria-* attributes is not an implementation detail. They are very much observable by the user of your website. There is a big difference between
I understand that it is tempting to short-circuit writing tests. If you have considered all the implications of considering aria-disabled and disabled equal then you can always use custom matchers in your code base. |
Yep that makes perfect sense, thanks for the detailed explanation! 👍
I know I added |
Sure. It's mostly digging through specifications though I'd imagine. I think the biggest difference is that something like |
just to ask ... would it be un-feasable to modify i.e. something would be disabled if it were |
You would have to find this out by reading specifications and researching if some behavior is defined by specifications or by vendor implementations etc. I'd imagine this would take some time. |
Wait wait, I very much agree with what's being said about With respect to add a |
I kind of agree with @gnapse. To be honest I'd never use something like I wasn't aware of |
So as an attempt to come to a bit of a conclusion (maybe only for myself)
As a user (and fan) of this library & the testing-library ecosystem as a whole, i did think that "mimic a browser" was the intent. I was under the impression (possibly incorrectly) that the philosophy behind the testing-library ecosystem was to encourage tests that mimic what a user would see and do. So following that logic i thought rolling these two together would be a sensible thing. This conversation has been really useful in showing that this thinking wasn't quite accurate, so instead would it be acceptable to add a new |
I seem to have failed communicating that doing that would be the exact opposite. If we would do that someone would need to put time and effort into compiling what
This sounds perfectly fine. This way you can't accidentally introduce (potentially ) breaking changes by switching from |
@eps1lon sorry, I've been reading back right to my initial query, i might have confused matters by not being very clear originally. (if not just ignore this message 😄 ) My proposal was never to remove any of the existing behaviour / matching semantics of the current
obviously there would be the potential for ambiguous
which could be detected and throw an error or some description explaining the ambiguity. this is exactly what id propose goes into a new |
tobedisabled
matchertoBeDisabled
matcher
It is not the original topic, but very similar issue. What is the recommendation for <!-- DOM -->
<div id="carousel">
<div class="slide fake-slide" aria-hidden="true">
<span>Text Slide #1</span>
</div>
<div class="slide">
<span>Text Slide #1</span>
</div>
<div class="slide fake-slide" aria-hidden="true">
<span>Text Slide #1</span>
</div>
</div> // test
const slidesDOM = getAllByText(container, 'Text Slide #1')
expect(slidesDOM[0]).not.toBeVisible();
expect(slidesDOM[1]).toBeVisible();
expect(slidesDOM[2]).not.toBeVisible(); See that the Even though they are rendered in the dom nodes, they are not visible for most users. They are only visible if they scroll very far in a single swipe, after which they remove the hidden attribute. I can't use the |
@andre-matulionis-ifood |
@andre-matulionis-ifood we may need a custom matcher for that because the semantics of |
Hi folks, Thanks for all your input. I don't think we're going to do this (adding support for the presence of Good luck! |
Isn't this testing for the explicit attribute? Whereas the proposal above should return true whether it has has aria-disabled or disabled (because the latter implies aria-disabled). Surely this is exactly the use case for the convenience methods such as .toBeDisabled()? If not, then all the above arguments should have already been applied and .toBeDisabled() would never have been added. If you explicitly want something with the disabled attribute, the check is |
The problem with
That button is still clickable and focusable. You can reach it when tabbing around the page, and click it with the mouse and with the keyboard. So having
This is not so simple. The For instance:
The test below passes: const buttonElement = screen.getByRole('button', { name: 'Click me' })
expect(buttonElement).toBeDisabled() The same cannot be said of |
Describe the feature you'd like:
i have custom buttons (SVG's with click handlers) which i want to ensure are disabled under certain circumstances. Since these elements have disabled styling I've been using the
aria-disabled
attrubtue for this purpose (two birds one stone)so i would like to be able to test as
expect(myCustomSvgButton).toBeDisabled()
Describe alternatives you've considered:
obiviously this is doable just now using
.toHaveAttribute
but i feel like this reduces the clarity of what's being checked and focuses on implementation details making the test brittle.on a side note, maybe encouraging the use of
aria-*
attrs for communication of more complex state in the DOM is not a bad thing?The text was updated successfully, but these errors were encountered: