-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[Modal] Fix persisting aria-hidden #16392
Conversation
test/utils/init.js
Outdated
chai.Assertion.addProperty('ariaHidden', function elementIsAccessible() { | ||
const element = utils.flag(this, 'object'); | ||
|
||
// "An element is considered hidden if it, or any of its ancestors are not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For integration test we could implement a custom matcher for hidden
content as well. It won't catch everything (since it requires layout) but a crude implementation could just join ariaHiden || !displayed || !visible
.
Details of bundle changes.Comparing: a0f0843...0a9c506
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we export ariaHidden from the ModalManager and use it in Modal?
The modal manager handles the active modals. In this case, the aria-hidden is used on a modal that is mounted in the DOM, and that will likely be active in the future. Removing the line breaks this test:
<Modal keepMounted open={false}
@@ -161,17 +161,17 @@ describe('ModalManager', () => { | |||
const modal2 = {}; | |||
modalManager.add(modal1, container3); | |||
modalManager.mount(modal1); | |||
assert.strictEqual(container3.children[0].getAttribute('aria-hidden'), 'true'); | |||
expect(container3.children[0]).to.be.ariaHidden; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of minimizing the API surface people have to know for contributing? Where does .ariaHidden come from? Would it be simpler with the native DOM API?
expect(container3.children[0]).to.be.ariaHidden; | |
expect(container3.children[0].getAttribute('aria-hidden')).to.equal('true'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have read the rest of the pull request. The native DOM API is not a good idea. I was confused by the magic behind the API.
What do you think of importing the aria-hidden helper function instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't scale very well (need to import all the matchers) and doesn't address the concern (knowledge is required in both cases). It's common to rely on injected matcher methods. Autocomplete should work (needs other PR) which helps with discoverability and teaching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh and yeah it helps debugging failing test. A simple boolean helper would not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to import all the matchers
I would hope a file test doesn't need to import all the matchers. For instance, will we need the aria-hidden helper outside of the modal context?
knowledge is required in both cases
It depends on the case. When writing the test case, knowledge is required in both cases. When reading the test case, the import can be followed. Considering we spend most of our time reading the test case, I find that value proposing interesting.
Oh and yeah it helps debugging failing test. A simple boolean helper would not.
Yeah, that wasn't a good idea from my part. However, does it invalidate the import helper point? Can we write the helper to run the assertions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fundamental issue. When something fails you need to understand how the code works not your test.
Yeah, I wish it was true, it's a great target!
Now, I haven't experienced that in practice in this codebase nor in any other. I have found myself needed to understand what was the initial situation, what was the actions and what was the assertions.
And tests are not always regression test.
Should they all be regression tests (i.e remove the ones that are not)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a reason why we say "test" and "regression test". One being more specific and less common therefore having the longer word. Regression test make little sense for behavior that's not observable to the user (e.g. component snapshot test, asserting instance fields).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have done a quick search on the topic. It seems that people define "regression test" as "when it fails, it tells you that the application no longer behaves the way it used to".
I was using the term in a broader context, closer to "acceptance test": "when it fails, it tells you that the application is not doing what the customer expects it to do".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly. And these tests next to our components are acceptance test that describe what's expected. The more declarative the better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only regression test I'm aware of that is valuable is the screenshot tests. I would be cautious with snapshot tests, it can quickly end-up like this: they take too much time to look, we accept the changes blindly.
accessibility check would include perceivability which requires layout
6c5660e
to
4f605a1
Compare
Not a fix yet just a failing test case.Opening this since I have a question: Why do we exportariaHidden
from the ModalManager and use it inModal
? Isn't the point of ModalManager that it manages this stuff in which case it shouldn't be exported?I suspected that the issue was with a rogue parent aria-hidden which is why I added a custom matcher (aria-hidden is inherited but not overwriteable).
Closes #16391
/cc @oliviertassinari