Skip to content

Commit 259fda8

Browse files
committed
feat: add expand/collapse animation to details element
1 parent e1d230b commit 259fda8

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

src/_details.scss

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,37 @@
2626

2727
}
2828

29+
// Animate content on open/close (progressive enhancement)
30+
// Outside @layer — ::details-content needs real specificity to override UA styles
31+
// Gate on ::details-content support (Safari 18.4+, Chrome 131+)
32+
@supports selector(details::details-content) {
33+
details::details-content {
34+
transition: opacity 0.3s ease,
35+
content-visibility 0.3s ease allow-discrete;
36+
opacity: 0;
37+
}
38+
39+
details[open]::details-content {
40+
opacity: 1;
41+
}
42+
43+
// Height animation where interpolate-size is supported (Chrome 129+)
44+
@supports (interpolate-size: allow-keywords) {
45+
details {
46+
interpolate-size: allow-keywords;
47+
}
48+
49+
details::details-content {
50+
transition: height 0.3s ease, opacity 0.3s ease,
51+
content-visibility 0.3s ease allow-discrete;
52+
height: 0;
53+
overflow: clip;
54+
}
55+
56+
details[open]::details-content {
57+
height: auto;
58+
}
59+
}
60+
}
61+
2962
}

0 commit comments

Comments
 (0)