@@ -53,14 +53,10 @@ let nextId = 0;
53
53
exportAs : 'cOffcanvas' ,
54
54
standalone : true ,
55
55
imports : [ A11yModule ] ,
56
- hostDirectives : [
57
- { directive : ThemeDirective , inputs : [ 'dark' ] }
58
- ] ,
59
- // eslint-disable-next-line @angular-eslint/no-host-metadata-property
56
+ hostDirectives : [ { directive : ThemeDirective , inputs : [ 'dark' ] } ] ,
60
57
host : { ngSkipHydration : 'true' }
61
58
} )
62
59
export class OffcanvasComponent implements OnInit , OnDestroy {
63
-
64
60
#destroyRef = inject ( DestroyRef ) ;
65
61
66
62
constructor (
@@ -196,7 +192,8 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
196
192
}
197
193
const element : Element = this . document . documentElement ;
198
194
const responsiveBreakpoint = this . responsive ;
199
- const breakpointValue = getComputedStyle ( element ) ?. getPropertyValue ( `--cui-breakpoint-${ responsiveBreakpoint . trim ( ) } ` ) ?? false ;
195
+ const breakpointValue =
196
+ getComputedStyle ( element ) ?. getPropertyValue ( `--cui-breakpoint-${ responsiveBreakpoint . trim ( ) } ` ) ?? false ;
200
197
return breakpointValue ? `${ parseFloat ( breakpointValue . trim ( ) ) - 0.02 } px` : false ;
201
198
}
202
199
@@ -229,12 +226,7 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
229
226
230
227
@HostListener ( 'document:keydown' , [ '$event' ] )
231
228
onKeyDownHandler ( event : KeyboardEvent ) : void {
232
- if (
233
- event . key === 'Escape' &&
234
- this . keyboard &&
235
- this . visible &&
236
- this . backdrop !== 'static'
237
- ) {
229
+ if ( event . key === 'Escape' && this . keyboard && this . visible && this . backdrop !== 'static' ) {
238
230
this . offcanvasService . toggle ( { show : false , id : this . id } ) ;
239
231
}
240
232
}
@@ -258,46 +250,36 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
258
250
}
259
251
260
252
private stateToggleSubscribe ( ) : void {
261
- this . offcanvasService . offcanvasState$
262
- . pipe (
263
- takeUntilDestroyed ( this . #destroyRef)
264
- )
265
- . subscribe ( ( action ) => {
266
- if ( this === action . offcanvas || this . id === action . id ) {
267
- if ( 'show' in action ) {
268
- this . visible =
269
- action ?. show === 'toggle' ? ! this . visible : action . show ;
270
- }
253
+ this . offcanvasService . offcanvasState$ . pipe ( takeUntilDestroyed ( this . #destroyRef) ) . subscribe ( ( action ) => {
254
+ if ( this === action . offcanvas || this . id === action . id ) {
255
+ if ( 'show' in action ) {
256
+ this . visible = action ?. show === 'toggle' ? ! this . visible : action . show ;
271
257
}
272
- } ) ;
258
+ }
259
+ } ) ;
273
260
}
274
261
275
262
private backdropClickSubscribe ( subscribe : boolean = true ) : void {
276
263
if ( subscribe ) {
277
- this . #backdropClickSubscription =
278
- this . backdropService . backdropClick$
279
- . pipe (
280
- takeUntilDestroyed ( this . #destroyRef)
281
- )
282
- . subscribe ( ( clicked ) => {
283
- this . offcanvasService . toggle ( { show : ! clicked , id : this . id } ) ;
284
- } ) ;
264
+ this . #backdropClickSubscription = this . backdropService . backdropClick$
265
+ . pipe ( takeUntilDestroyed ( this . #destroyRef) )
266
+ . subscribe ( ( clicked ) => {
267
+ this . offcanvasService . toggle ( { show : ! clicked , id : this . id } ) ;
268
+ } ) ;
285
269
} else {
286
270
this . #backdropClickSubscription?. unsubscribe ( ) ;
287
271
}
288
272
}
289
273
290
274
private setBackdrop ( setBackdrop : boolean | 'static' ) : void {
291
- this . #activeBackdrop = ! ! setBackdrop ? this . backdropService . setBackdrop ( 'offcanvas' )
292
- : this . backdropService . clearBackdrop ( this . #activeBackdrop ) ;
293
- setBackdrop === true ? this . backdropClickSubscribe ( )
294
- : this . backdropClickSubscribe ( false ) ;
275
+ this . #activeBackdrop = ! ! setBackdrop
276
+ ? this . backdropService . setBackdrop ( 'offcanvas' )
277
+ : this . backdropService . clearBackdrop ( this . #activeBackdrop ) ;
278
+ setBackdrop === true ? this . backdropClickSubscribe ( ) : this . backdropClickSubscribe ( false ) ;
295
279
}
296
280
297
281
private layoutChangeSubscribe ( subscribe : boolean = true ) : void {
298
-
299
282
if ( subscribe ) {
300
-
301
283
if ( ! this . responsiveBreakpoint ) {
302
284
return ;
303
285
}
@@ -308,14 +290,12 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
308
290
309
291
this . #layoutChangeSubscription = layoutChanges
310
292
. pipe (
311
- filter ( breakpointState => ! breakpointState . matches ) ,
293
+ filter ( ( breakpointState ) => ! breakpointState . matches ) ,
312
294
takeUntilDestroyed ( this . #destroyRef)
313
295
)
314
- . subscribe (
315
- ( breakpointState : BreakpointState ) => {
316
- this . visible = breakpointState . matches ;
317
- }
318
- ) ;
296
+ . subscribe ( ( breakpointState : BreakpointState ) => {
297
+ this . visible = breakpointState . matches ;
298
+ } ) ;
319
299
} else {
320
300
this . #layoutChangeSubscription?. unsubscribe ( ) ;
321
301
}
0 commit comments