Skip to content

Commit adb98d5

Browse files
committed
fix(toggle): use workaround to apply host bound classes and attributes
1 parent 2837059 commit adb98d5

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

projects/igniteui-angular/src/lib/directives/toggle/toggle.directive.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import {
2-
afterNextRender,
32
ChangeDetectorRef,
43
Directive,
54
ElementRef,
65
EventEmitter,
76
HostListener,
8-
inject,
97
Inject,
10-
Injector,
118
Input,
129
OnDestroy,
1310
OnInit,
1411
Optional,
1512
Output,
16-
runInInjectionContext
1713
} from '@angular/core';
1814
import { AbsoluteScrollStrategy } from '../../services/overlay/scroll/absolute-scroll-strategy';
1915
import { CancelableBrowserEventArgs, IBaseEventArgs, PlatformUtil } from '../../core/utils';
@@ -201,7 +197,6 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
201197
private _overlayClosingSub: Subscription;
202198
private _overlayClosedSub: Subscription;
203199
private _overlayContentAppendedSub: Subscription;
204-
private _injector = inject(Injector);
205200

206201
/**
207202
* @hidden
@@ -234,27 +229,34 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
234229

235230
this._collapsed = false;
236231

237-
runInInjectionContext(this._injector, () =>{
238-
afterNextRender(() => {
239-
if (!info) {
240-
this.unsubscribe();
241-
this.subscribe();
242-
this._overlayId = this.overlayService.attach(this.elementRef, overlaySettings);
243-
}
232+
// TODO: this is a workaround for the issue introduced by Angular's with Ivy renderer.
233+
// When calling detectChanges(), Angular marks the element for check, but does not update the classes
234+
// immediately, which causes the overlay to calculate incorrect dimensions of target element.
235+
// Overlay show should be called in the next tick to ensure the classes are updated and target element is measured correctly.
236+
// Note: across the codebase, each host binding should be checked and similar fix applied if needed!!!
237+
this.elementRef.nativeElement.className = this.elementRef.nativeElement.className.replace('igx-toggle--hidden', 'igx-toggle');
238+
this.elementRef.nativeElement.className = this.elementRef.nativeElement.className.replace('igx-toggle--hidden-webkit', 'igx-toggle');
239+
this.elementRef.nativeElement.removeAttribute('aria-hidden');
244240

245-
const args: ToggleViewCancelableEventArgs = { cancel: false, owner: this, id: this._overlayId };
246-
this.opening.emit(args);
247-
if (args.cancel) {
248-
this.unsubscribe();
249-
this.overlayService.detach(this._overlayId);
250-
this._collapsed = true;
251-
delete this._overlayId;
252-
this.cdr.detectChanges();
253-
return;
254-
}
255-
this.overlayService.show(this._overlayId, overlaySettings);
256-
});
257-
});
241+
this.cdr.detectChanges();
242+
243+
if (!info) {
244+
this.unsubscribe();
245+
this.subscribe();
246+
this._overlayId = this.overlayService.attach(this.elementRef, overlaySettings);
247+
}
248+
249+
const args: ToggleViewCancelableEventArgs = { cancel: false, owner: this, id: this._overlayId };
250+
this.opening.emit(args);
251+
if (args.cancel) {
252+
this.unsubscribe();
253+
this.overlayService.detach(this._overlayId);
254+
this._collapsed = true;
255+
delete this._overlayId;
256+
this.cdr.detectChanges();
257+
return;
258+
}
259+
this.overlayService.show(this._overlayId, overlaySettings);
258260
}
259261

260262
/**

projects/igniteui-angular/src/lib/services/overlay/overlay.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,19 @@ export class IgxOverlayService implements OnDestroy {
431431
}
432432
}
433433
this.updateSize(info);
434+
const openAnimation = info.settings.positionStrategy.settings.openAnimation;
435+
const closeAnimation = info.settings.positionStrategy.settings.closeAnimation;
434436
info.settings.positionStrategy.position(
435437
info.elementRef.nativeElement.parentElement,
436438
{ width: info.initialSize.width, height: info.initialSize.height },
437439
this._document,
438440
true,
439441
info.settings.target);
440-
this.addModalClasses(info);
442+
if (openAnimation !== info.settings.positionStrategy.settings.openAnimation ||
443+
closeAnimation !== info.settings.positionStrategy.settings.closeAnimation){
444+
this.addModalClasses(info);
445+
}
446+
this.buildAnimationPlayers(info);
441447
if (info.settings.positionStrategy.settings.openAnimation) {
442448
// TODO: should we build players again. This was already done in attach!!!
443449
// this.buildAnimationPlayers(info);

0 commit comments

Comments
 (0)