@@ -3,14 +3,13 @@ import {
33 Directive ,
44 ElementRef ,
55 EventEmitter ,
6- HostBinding ,
76 HostListener ,
87 Inject ,
98 Input ,
109 OnDestroy ,
1110 OnInit ,
1211 Optional ,
13- Output
12+ Output ,
1413} from '@angular/core' ;
1514import { AbsoluteScrollStrategy } from '../../services/overlay/scroll/absolute-scroll-strategy' ;
1615import { CancelableBrowserEventArgs , IBaseEventArgs , PlatformUtil } from '../../core/utils' ;
@@ -34,7 +33,13 @@ export interface ToggleViewCancelableEventArgs extends ToggleViewEventArgs, Canc
3433@Directive ( {
3534 exportAs : 'toggle' ,
3635 selector : '[igxToggle]' ,
37- standalone : true
36+ standalone : true ,
37+ host : {
38+ '[class.igx-toggle--hidden]' : 'hiddenClass' ,
39+ '[attr.aria-hidden]' : 'hiddenClass' ,
40+ '[class.igx-toggle--hidden-webkit]' : 'hiddenWebkitClass' ,
41+ '[class.igx-toggle]' : 'defaultClass'
42+ }
3843} )
3944export class IgxToggleDirective implements IToggleView , OnInit , OnDestroy {
4045 /**
@@ -159,13 +164,13 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
159164 /**
160165 * @hidden
161166 */
162- @HostBinding ( 'class.igx-toggle--hidden' )
163- @HostBinding ( 'attr.aria-hidden' )
164167 public get hiddenClass ( ) {
165168 return this . collapsed ;
166169 }
167170
168- @HostBinding ( 'class.igx-toggle--hidden-webkit' )
171+ /**
172+ * @hidden
173+ */
169174 public get hiddenWebkitClass ( ) {
170175 const isSafari = this . platform ?. isSafari ;
171176 const browserVersion = this . platform ?. browserVersion ;
@@ -176,7 +181,6 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
176181 /**
177182 * @hidden
178183 */
179- @HostBinding ( 'class.igx-toggle' )
180184 public get defaultClass ( ) {
181185 return ! this . collapsed ;
182186 }
@@ -224,6 +228,16 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
224228 }
225229
226230 this . _collapsed = false ;
231+
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' ) ;
240+
227241 this . cdr . detectChanges ( ) ;
228242
229243 if ( ! info ) {
0 commit comments