Skip to content

Commit 7e98f59

Browse files
committed
fix(sidebar): emit visible event on mobile layout change
1 parent 13c3d32 commit 7e98f59

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { SidebarBackdropService } from '../sidebar-backdrop/sidebar-backdrop.ser
2222
@Component({
2323
selector: 'c-sidebar',
2424
exportAs: 'cSidebar',
25-
template: '<ng-content></ng-content>',
25+
template: '<ng-content></ng-content>'
2626
})
2727
export class SidebarComponent implements OnChanges, OnDestroy, OnInit {
2828

@@ -58,6 +58,7 @@ export class SidebarComponent implements OnChanges, OnDestroy, OnInit {
5858
set narrow(value: boolean) {
5959
this._narrow = coerceBooleanProperty(value);
6060
}
61+
6162
get narrow() {
6263
return this._narrow;
6364
}
@@ -70,6 +71,7 @@ export class SidebarComponent implements OnChanges, OnDestroy, OnInit {
7071
set overlaid(value: boolean) {
7172
this._overlaid = coerceBooleanProperty(value);
7273
}
74+
7375
get overlaid() {
7476
return this._overlaid;
7577
}
@@ -92,6 +94,7 @@ export class SidebarComponent implements OnChanges, OnDestroy, OnInit {
9294
set unfoldable(value: boolean) {
9395
this._unfoldable = coerceBooleanProperty(value);
9496
}
97+
9598
get unfoldable() {
9699
return this._unfoldable;
97100
}
@@ -101,9 +104,13 @@ export class SidebarComponent implements OnChanges, OnDestroy, OnInit {
101104
*/
102105
@Input()
103106
set visible(value: boolean) {
104-
this._visible = coerceBooleanProperty(value);
105-
this.visibleChange.emit(this._visible);
107+
const visible = coerceBooleanProperty(value);
108+
if (this._visible !== visible) {
109+
this._visible = visible;
110+
this.visibleChange.emit(this._visible);
111+
}
106112
}
113+
107114
get visible() {
108115
return this._visible;
109116
}
@@ -124,6 +131,8 @@ export class SidebarComponent implements OnChanges, OnDestroy, OnInit {
124131
newState.unfoldable = !this.state.unfoldable;
125132
this.unfoldable = newState.unfoldable;
126133
}
134+
} else {
135+
this.visible = (newState.visible ?? this.visible) && !this.overlaid;
127136
}
128137
this.state = {
129138
...this.state,
@@ -155,12 +164,12 @@ export class SidebarComponent implements OnChanges, OnDestroy, OnInit {
155164

156165
@HostBinding('class')
157166
get getClasses(): any {
158-
const {mobile, unfoldable, visible} = this.sidebarState;
167+
const { mobile, unfoldable, visible } = this.sidebarState;
159168
return {
160169
sidebar: true,
161170
'sidebar-fixed': this.position === 'fixed' && !mobile,
162171
'sidebar-narrow': this.narrow && !this.unfoldable,
163-
'sidebar-narrow-unfoldable': unfoldable,
172+
'sidebar-narrow-unfoldable': this.unfoldable,
164173
'sidebar-overlaid': this.overlaid,
165174
[`sidebar-${this.size}`]: !!this.size,
166175
show: visible && this.onMobile,
@@ -232,12 +241,13 @@ export class SidebarComponent implements OnChanges, OnDestroy, OnInit {
232241

233242
this.layoutChangeSubscription = layoutChanges.subscribe((result: BreakpointState) => {
234243
const isOnMobile = result.breakpoints[onMobile];
244+
const isUnfoldable = isOnMobile ? false : this.unfoldable;
235245
if (this.onMobile !== isOnMobile) {
236246
this.onMobile = isOnMobile;
237247
this.sidebarService.toggle({
238248
mobile: isOnMobile,
239-
unfoldable: isOnMobile ? false : this.unfoldable,
240-
visible: isOnMobile ? false : this.visible,
249+
unfoldable: isUnfoldable,
250+
visible: (!isOnMobile) || isUnfoldable,
241251
sidebar: this
242252
});
243253
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy