Skip to content

Commit c3e05da

Browse files
committed
fix(sidebar-nav-group): missing animation
1 parent fd52e03 commit c3e05da

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

projects/coreui-angular/src/lib/sidebar/sidebar-nav/sidebar-nav-group.component.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
</a>
88
<c-sidebar-nav
99
[groupItems]="true"
10-
[navItems]="navItems">
10+
[navItems]="navItems"
11+
[@openClose]="open ? 'open' : 'closed'"
12+
(@openClose.start)="onAnimationStart($event)"
13+
(@openClose.done)="onAnimationDone($event)"
14+
[ngStyle]="display"
15+
>
1116
</c-sidebar-nav>
1217

1318
<ng-template #iconTemplate let-item>

projects/coreui-angular/src/lib/sidebar/sidebar-nav/sidebar-nav.component.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ import { SidebarService } from '../sidebar.service';
1818
import { SidebarComponent } from '../sidebar/sidebar.component';
1919
import { Observable, Subscription } from 'rxjs';
2020
import { filter } from 'rxjs/operators';
21+
import { animate, AnimationEvent, state, style, transition, trigger } from '@angular/animations';
2122

2223
@Component({
2324
selector: 'c-sidebar-nav',
2425
templateUrl: './sidebar-nav.component.html',
2526
styleUrls: ['./sidebar-nav.component.scss']
26-
})
27+
})
2728
export class SidebarNavComponent implements OnChanges {
2829
@Input() navItems?: INavData[] = [];
2930
@Input() dropdownMode?: 'closeInactive' | 'noAction' | 'openActive' = 'closeInactive';
@@ -63,7 +64,7 @@ export class SidebarNavComponent implements OnChanges {
6364
public hideMobile(): void {
6465
// todo: proper scrollIntoView() after NavigationEnd
6566
if (this.sidebar && this.sidebar.sidebarState.mobile) {
66-
this.sidebarService.toggle({toggle: 'visible', sidebar: this.sidebar});
67+
this.sidebarService.toggle({ toggle: 'visible', sidebar: this.sidebar });
6768
}
6869
}
6970
}
@@ -72,7 +73,20 @@ export class SidebarNavComponent implements OnChanges {
7273
selector: 'c-sidebar-nav-group',
7374
templateUrl: './sidebar-nav-group.component.html',
7475
styleUrls: ['./sidebar-nav-group.component.scss'],
75-
providers: [ SidebarNavHelper ]
76+
providers: [SidebarNavHelper],
77+
animations: [
78+
trigger('openClose', [
79+
state('open', style({
80+
height: '*'
81+
})),
82+
state('closed', style({
83+
height: '0px'
84+
})),
85+
transition('open <=> closed', [
86+
animate('.15s ease')
87+
])
88+
])
89+
]
7690
})
7791
export class SidebarNavGroupComponent implements OnInit, OnDestroy {
7892
@Input() item: any;
@@ -85,7 +99,7 @@ export class SidebarNavGroupComponent implements OnInit, OnDestroy {
8599
get hostClasses(): any {
86100
return {
87101
'nav-group': true,
88-
show: this.open,
102+
show: this.open
89103
};
90104
}
91105

@@ -96,8 +110,9 @@ export class SidebarNavGroupComponent implements OnInit, OnDestroy {
96110
navSubscription: Subscription;
97111

98112
// @ts-ignore
99-
private open: boolean;
113+
public open: boolean;
100114
public navItems: INavData[] = [];
115+
public display: any = { display: 'block' };
101116

102117
constructor(
103118
private router: Router,
@@ -145,4 +160,18 @@ export class SidebarNavGroupComponent implements OnInit, OnDestroy {
145160
ngOnDestroy(): void {
146161
this.navSubscription.unsubscribe();
147162
}
163+
164+
onAnimationStart($event: AnimationEvent) {
165+
setTimeout(() => {
166+
this.display = { display: 'block' };
167+
});
168+
}
169+
170+
onAnimationDone($event: AnimationEvent) {
171+
if ($event.toState === 'closed') {
172+
setTimeout(() => {
173+
this.display = null;
174+
});
175+
}
176+
}
148177
}

0 commit comments

Comments
 (0)