|
1 | 1 | import { |
2 | | - afterNextRender, |
3 | 2 | ChangeDetectorRef, |
4 | 3 | Directive, |
5 | 4 | ElementRef, |
6 | 5 | EventEmitter, |
7 | 6 | HostListener, |
8 | | - inject, |
9 | 7 | Inject, |
10 | | - Injector, |
11 | 8 | Input, |
12 | 9 | OnDestroy, |
13 | 10 | OnInit, |
14 | 11 | Optional, |
15 | 12 | Output, |
16 | | - runInInjectionContext |
17 | 13 | } from '@angular/core'; |
18 | 14 | import { AbsoluteScrollStrategy } from '../../services/overlay/scroll/absolute-scroll-strategy'; |
19 | 15 | import { CancelableBrowserEventArgs, IBaseEventArgs, PlatformUtil } from '../../core/utils'; |
@@ -201,7 +197,6 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy { |
201 | 197 | private _overlayClosingSub: Subscription; |
202 | 198 | private _overlayClosedSub: Subscription; |
203 | 199 | private _overlayContentAppendedSub: Subscription; |
204 | | - private _injector = inject(Injector); |
205 | 200 |
|
206 | 201 | /** |
207 | 202 | * @hidden |
@@ -234,27 +229,34 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy { |
234 | 229 |
|
235 | 230 | this._collapsed = false; |
236 | 231 |
|
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'); |
244 | 240 |
|
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); |
258 | 260 | } |
259 | 261 |
|
260 | 262 | /** |
|
0 commit comments