@@ -7,16 +7,14 @@ import {
7
7
DestroyRef ,
8
8
effect ,
9
9
ElementRef ,
10
- EventEmitter ,
11
10
inject ,
12
11
input ,
12
+ linkedSignal ,
13
13
OnDestroy ,
14
14
OnInit ,
15
15
output ,
16
16
PLATFORM_ID ,
17
- Renderer2 ,
18
- signal ,
19
- untracked
17
+ Renderer2
20
18
} from '@angular/core' ;
21
19
import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
22
20
import { A11yModule } from '@angular/cdk/a11y' ;
@@ -56,7 +54,7 @@ let nextId = 0;
56
54
hostDirectives : [ { directive : ThemeDirective , inputs : [ 'dark' ] } ] ,
57
55
host : {
58
56
ngSkipHydration : 'true' ,
59
- '[@showHide]' : 'animateTrigger ' ,
57
+ '[@showHide]' : 'this.visible() ? "visible" : "hidden" ' ,
60
58
'[attr.id]' : 'id()' ,
61
59
'[attr.inert]' : 'ariaHidden() || null' ,
62
60
'[attr.role]' : 'role()' ,
@@ -125,7 +123,6 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
125
123
#activeBackdrop! : HTMLDivElement ;
126
124
#backdropClickSubscription! : Subscription ;
127
125
#layoutChangeSubscription! : Subscription ;
128
- #show = false ;
129
126
130
127
/**
131
128
* Allow body scrolling while offcanvas is visible.
@@ -141,15 +138,11 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
141
138
*/
142
139
readonly visibleInput = input ( false , { transform : booleanAttribute , alias : 'visible' } ) ;
143
140
144
- readonly visibleInputEffect = effect ( ( ) => {
145
- const visible = this . visibleInput ( ) ;
146
- untracked ( ( ) => {
147
- this . visible . set ( visible ) ;
148
- } ) ;
141
+ readonly visible = linkedSignal ( {
142
+ source : ( ) => this . visibleInput ( ) ,
143
+ computation : ( value ) => value
149
144
} ) ;
150
145
151
- readonly visible = signal ( false ) ;
152
-
153
146
readonly visibleEffect = effect ( ( ) => {
154
147
const visible = this . visible ( ) ;
155
148
if ( visible ) {
@@ -164,18 +157,19 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
164
157
165
158
/**
166
159
* Event triggered on visible change.
167
- * @return EventEmitter <boolean>
160
+ * @return <boolean>
168
161
*/
169
162
readonly visibleChange = output < boolean > ( ) ;
170
163
171
164
readonly hostClasses = computed ( ( ) => {
172
165
const responsive = this . responsive ( ) ;
173
166
const placement = this . placement ( ) ;
167
+ const visible = this . visible ( ) ;
174
168
return {
175
169
offcanvas : typeof responsive === 'boolean' ,
176
170
[ `offcanvas-${ responsive } ` ] : typeof responsive !== 'boolean' ,
177
171
[ `offcanvas-${ placement } ` ] : ! ! placement ,
178
- show : this . show
172
+ show : visible
179
173
} as Record < string , boolean > ;
180
174
} ) ;
181
175
@@ -187,16 +181,12 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
187
181
return '-1' ;
188
182
}
189
183
190
- get animateTrigger ( ) : string {
191
- return this . visible ( ) ? 'visible' : 'hidden' ;
192
- }
193
-
194
184
get show ( ) : boolean {
195
- return this . visible ( ) && this . #show ;
185
+ return this . visible ( ) ;
196
186
}
197
187
198
188
set show ( value : boolean ) {
199
- this . #show = value ;
189
+ this . visible . set ( value ) ;
200
190
}
201
191
202
192
get responsiveBreakpoint ( ) : string | false {
0 commit comments