user-event icon indicating copy to clipboard operation
user-event copied to clipboard

respect elements that are hidden by <details>

Open VinceMalone opened this issue 1 year ago • 1 comments

What:

stop considering elements hidden by a collapsed <details> element to be visible or focusable, via getTabDestination().

for example, user.tab() should not focus elements hidden by a collapsed details ancestor.

Why:

same reasons for how .toBeVisible works in jest-dom

An element is visible if all the following conditions are met:

  • […]
  • if <details /> it has the open attribute

given the following code:

<details>
  <button id="hidden"></button>
</details>
<details open>
  <button id="visible"></button>
</details>

button#hidden should not be considered visible, nor should it be focusable, but button#visible should.

Note the single exception for this is a summary element that is a direct descendant of a details element. the summary element acts as an [always visible] trigger for controlling the expanded state of the details element.

How:

at least for conveniences sake, i copied the same logic from jest-dom for determining if an element should be considered visible when walking the element tree (with one exception: looking for the hidden attribute — this caused an issue that i think might be a bug in that library)

Checklist:

  • [ ] Documentation
  • [x] Tests
  • [x] Ready to be merged

VinceMalone avatar Sep 15 '23 20:09 VinceMalone