Skip to content

Commit 5a2592e

Browse files
committed
fix(offcanvas): offcanvas hides on animation.done toState visible, refactor
1 parent 9ee76df commit 5a2592e

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

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

+11-21
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ import {
77
DestroyRef,
88
effect,
99
ElementRef,
10-
EventEmitter,
1110
inject,
1211
input,
12+
linkedSignal,
1313
OnDestroy,
1414
OnInit,
1515
output,
1616
PLATFORM_ID,
17-
Renderer2,
18-
signal,
19-
untracked
17+
Renderer2
2018
} from '@angular/core';
2119
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
2220
import { A11yModule } from '@angular/cdk/a11y';
@@ -56,7 +54,7 @@ let nextId = 0;
5654
hostDirectives: [{ directive: ThemeDirective, inputs: ['dark'] }],
5755
host: {
5856
ngSkipHydration: 'true',
59-
'[@showHide]': 'animateTrigger',
57+
'[@showHide]': 'this.visible() ? "visible" : "hidden"',
6058
'[attr.id]': 'id()',
6159
'[attr.inert]': 'ariaHidden() || null',
6260
'[attr.role]': 'role()',
@@ -125,7 +123,6 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
125123
#activeBackdrop!: HTMLDivElement;
126124
#backdropClickSubscription!: Subscription;
127125
#layoutChangeSubscription!: Subscription;
128-
#show = false;
129126

130127
/**
131128
* Allow body scrolling while offcanvas is visible.
@@ -141,15 +138,11 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
141138
*/
142139
readonly visibleInput = input(false, { transform: booleanAttribute, alias: 'visible' });
143140

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
149144
});
150145

151-
readonly visible = signal(false);
152-
153146
readonly visibleEffect = effect(() => {
154147
const visible = this.visible();
155148
if (visible) {
@@ -164,18 +157,19 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
164157

165158
/**
166159
* Event triggered on visible change.
167-
* @return EventEmitter<boolean>
160+
* @return <boolean>
168161
*/
169162
readonly visibleChange = output<boolean>();
170163

171164
readonly hostClasses = computed(() => {
172165
const responsive = this.responsive();
173166
const placement = this.placement();
167+
const visible = this.visible();
174168
return {
175169
offcanvas: typeof responsive === 'boolean',
176170
[`offcanvas-${responsive}`]: typeof responsive !== 'boolean',
177171
[`offcanvas-${placement}`]: !!placement,
178-
show: this.show
172+
show: visible
179173
} as Record<string, boolean>;
180174
});
181175

@@ -187,16 +181,12 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
187181
return '-1';
188182
}
189183

190-
get animateTrigger(): string {
191-
return this.visible() ? 'visible' : 'hidden';
192-
}
193-
194184
get show(): boolean {
195-
return this.visible() && this.#show;
185+
return this.visible();
196186
}
197187

198188
set show(value: boolean) {
199-
this.#show = value;
189+
this.visible.set(value);
200190
}
201191

202192
get responsiveBreakpoint(): string | false {

0 commit comments

Comments
 (0)