Skip to content

Commit b64f03d

Browse files
authored
Treat closed <details> non-summary descendants as non-visible (#317)
1 parent 8d37d1f commit b64f03d

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

lib/capybara/cuprite/javascripts/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,16 @@ class Cuprite {
8585
if (style.display === "none" || style.visibility === "hidden" || parseFloat(style.opacity) === 0) {
8686
return false;
8787
}
88-
node = node.parentElement ?? (node.getRootNode() instanceof ShadowRoot && node.getRootNode());
88+
89+
let parent = node.parentElement;
90+
if (parent && parent.tagName === "DETAILS" && !parent.open) {
91+
// In a closed <details> only the first <summary> (and its subtree) is rendered.
92+
if (node !== parent.querySelector(":scope > summary")) {
93+
return false;
94+
}
95+
}
96+
97+
node = parent ?? (node.getRootNode() instanceof ShadowRoot && node.getRootNode());
8998
}
9099
}
91100

spec/spec_helper.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ module TestSessions
5656
node Element#drop can drop strings
5757
node Element#drop can drop multiple strings
5858
node Element#drop can drop a pathname
59-
node #visible? details non-summary descendants should be non-visible
60-
node #visible? works when details is toggled open and closed
6159
node #set should submit single text input forms if ended with
6260
#has_field with valid should be false if field is invalid
6361
#has_element? should be true if the given element is on the page

0 commit comments

Comments
 (0)