Skip to content
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import {
afterNextRender,
ChangeDetectorRef,
Directive,
ElementRef,
EventEmitter,
HostListener,
inject,
Inject,
Injector,
Input,
OnDestroy,
OnInit,
Optional,
Output,
runInInjectionContext
Output
} from '@angular/core';
import { AbsoluteScrollStrategy } from '../../services/overlay/scroll/absolute-scroll-strategy';
import { CancelableBrowserEventArgs, IBaseEventArgs, PlatformUtil } from '../../core/utils';
Expand Down Expand Up @@ -201,7 +197,6 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
private _overlayClosingSub: Subscription;
private _overlayClosedSub: Subscription;
private _overlayContentAppendedSub: Subscription;
private _injector = inject(Injector);

/**
* @hidden
Expand Down Expand Up @@ -233,28 +228,27 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
}

this._collapsed = false;
this.cdr.detectChanges();
// Call detectChanges twice to ensure host bindings are updated in post-Ivy Angular
this.cdr.detectChanges();
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Calling detectChanges() twice is a code smell that suggests relying on implementation details of Angular's change detection. Consider using ApplicationRef.tick() or restructuring the code to avoid needing multiple synchronous change detection cycles. If this is truly necessary, the comment should explain why two calls are needed (what happens after the first that requires a second) rather than just stating what the code does.

Suggested change
this.cdr.detectChanges();
// Call detectChanges twice to ensure host bindings are updated in post-Ivy Angular
this.cdr.detectChanges();
// Call detectChanges to ensure host bindings are updated in post-Ivy Angular.
this.cdr.detectChanges();

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
I really do not like this and it breaks again the auto position strategy. What you need to do is to fix the failing tests. Before the change in #16429 there were many test which expects toggle target to exist right after toggle.open is called. This is not true after the change in #16429. What is needed is to make the failing test to wait until toggle target is visible. This is what you need to do.
Update your PR and fix the failing test by making them wait as needed.


runInInjectionContext(this._injector, () =>{
afterNextRender(() => {
if (!info) {
this.unsubscribe();
this.subscribe();
this._overlayId = this.overlayService.attach(this.elementRef, overlaySettings);
}
if (!info) {
this.unsubscribe();
this.subscribe();
this._overlayId = this.overlayService.attach(this.elementRef, overlaySettings);
}

const args: ToggleViewCancelableEventArgs = { cancel: false, owner: this, id: this._overlayId };
this.opening.emit(args);
if (args.cancel) {
this.unsubscribe();
this.overlayService.detach(this._overlayId);
this._collapsed = true;
delete this._overlayId;
this.cdr.detectChanges();
return;
}
this.overlayService.show(this._overlayId, overlaySettings);
});
});
const args: ToggleViewCancelableEventArgs = { cancel: false, owner: this, id: this._overlayId };
this.opening.emit(args);
if (args.cancel) {
this.unsubscribe();
this.overlayService.detach(this._overlayId);
this._collapsed = true;
delete this._overlayId;
this.cdr.detectChanges();
return;
}
this.overlayService.show(this._overlayId, overlaySettings);
}

/**
Expand Down