Skip to content

Commit aa2106d

Browse files
committed
refactor(accordion): use native CSS animations
1 parent 89ca3af commit aa2106d

11 files changed

+52
-82
lines changed

playwright/snapshots/si-side-panel.spec.ts-snapshots/si-side-panel--si-side-panel--over-mode-no-backdrop.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
- button "Hey there" [expanded]
55
- region "Hey there": And here we have some content
66
- button "Another one"
7-
- region "Another one"
87
- button "Number three"
9-
- region "Number three"
108
- banner:
119
- link "Siemens logo":
1210
- /url: "#/"

playwright/snapshots/si-side-panel.spec.ts-snapshots/si-side-panel--si-side-panel--over-mode.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
- button "Hey there" [expanded]
55
- region "Hey there": And here we have some content
66
- button "Another one"
7-
- region "Another one"
87
- button "Number three"
9-
- region "Number three"
108
- banner:
119
- link "Siemens logo":
1210
- /url: "#/"

playwright/snapshots/si-side-panel.spec.ts-snapshots/si-side-panel--si-side-panel--scroll-mode.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
- button "Hey there" [expanded]
55
- region "Hey there": And here we have some content
66
- button "Another one"
7-
- region "Another one"
87
- button "Number three"
9-
- region "Number three"
108
- banner:
119
- link "Siemens logo":
1210
- /url: "#/"

playwright/snapshots/si-side-panel.spec.ts-snapshots/si-side-panel--si-side-panel-collapsible--open.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
- button "Properties 5" [expanded]
1414
- region "Properties 5": And here we have some content
1515
- button "Documents"
16-
- region "Documents"
1716
- button "Graphics"
18-
- region "Graphics"
1917
- banner:
2018
- link "Siemens logo":
2119
- /url: "#/"

playwright/snapshots/static.spec.ts-snapshots/si-accordion--si-accordion-base-1.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@
22
- button "Hey there" [expanded]
33
- region "Hey there": Here is some content
44
- button "Another one 5"
5-
- region "Another one 5"
65
- button "Number three"
7-
- region "Number three"
8-
- button "Heading via content projection"
9-
- region "Heading via content projection"
6+
- button "Heading via content projection"

playwright/snapshots/static.spec.ts-snapshots/si-accordion--si-accordion.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@
22
- button "Hey there" [expanded]
33
- region "Hey there": Here is some content
44
- button "Another one 5"
5-
- region "Another one 5"
65
- button "Number three"
7-
- region "Number three"
8-
- button "Heading via content projection"
9-
- region "Heading via content projection"
6+
- button "Heading via content projection"
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
- button "Building automation"
2-
- region "Building automation"
32
- button "Building infrastructure"
4-
- region "Building infrastructure"
53
- button "Fire"
6-
- region "Fire"
74
- button "Security"
8-
- region "Security"
95
- button "Energy management"
10-
- region "Energy management"
11-
- button "Management system" [disabled]
12-
- region "Management system"
6+
- button "Management system" [disabled]
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
- button "Hey there"
2-
- region "Hey there"
32
- button "Another one"
4-
- region "Another one"
53
- button "Number three"
6-
- region "Number three"
74
- button "This is disabled" [disabled]
8-
- region "This is disabled"
9-
- button "Heading via content projection"
10-
- region "Heading via content projection"
5+
- button "Heading via content projection"

projects/element-ng/accordion/si-collapsible-panel.component.html

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[title]="hcollapsed() ? (heading() | translate) : ''"
99
[attr.aria-expanded]="opened() && !hcollapsed()"
1010
[attr.aria-disabled]="disabled()"
11-
[attr.aria-controls]="controlId"
11+
[attr.aria-controls]="opened() ? controlId : null"
1212
[attr.aria-label]="hcollapsed() ? (heading() | translate) : ''"
1313
(keydown)="keydown($event)"
1414
(click)="doToggle($event)"
@@ -36,20 +36,20 @@
3636
<si-icon class="icon dropdown-caret" [icon]="icons.elementDown2" />
3737
</span>
3838
</div>
39-
<div
40-
#content
41-
role="region"
42-
[id]="controlId"
43-
[class]="`collapsible-content ${contentBgClasses()}`"
44-
[@showHide]="showHide"
45-
[attr.aria-labelledby]="headerId"
46-
[class.full-height]="fullHeight()"
47-
>
48-
@if (opened()) {
39+
@if (opened()) {
40+
<div
41+
#content
42+
role="region"
43+
animate.leave="content-leave"
44+
[id]="controlId"
45+
[class]="`collapsible-content ${contentBgClasses()}`"
46+
[attr.aria-labelledby]="headerId"
47+
[class.full-height]="fullHeight()"
48+
>
4949
<div>
5050
<div [class]="contentCssClasses()">
5151
<ng-content />
5252
</div>
5353
</div>
54-
}
55-
</div>
54+
</div>
55+
}

projects/element-ng/accordion/si-collapsible-panel.component.scss

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,28 @@
8686

8787
.collapsible-content {
8888
overflow: hidden;
89-
display: flex;
90-
flex-direction: column;
89+
display: grid;
90+
grid-template-rows: 1fr;
91+
transition: grid-template-rows variables.element-transition-duration(0.5s) ease-in;
9192
background: variables.$element-base-1;
9293
border-end-start-radius: var(--__radius);
9394
border-end-end-radius: var(--__radius);
9495

96+
@starting-style {
97+
grid-template-rows: 0fr;
98+
}
99+
95100
&.full-height {
96101
// cannot use class overflow-auto, as it is using !important which is breaking the animation
97102
overflow: auto;
98103
}
104+
105+
&.content-leave {
106+
grid-template-rows: 0fr;
107+
}
108+
109+
> * {
110+
// The min-block-size is required to support the transition on grid-template-rows
111+
min-block-size: 0;
112+
}
99113
}

0 commit comments

Comments
 (0)