@@ -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 'igniteui-angular/core' ;
1615import { CancelableBrowserEventArgs , IBaseEventArgs , PlatformUtil } from 'igniteui-angular/core' ;
@@ -38,7 +37,13 @@ export interface ToggleViewCancelableEventArgs extends ToggleViewEventArgs, Canc
3837@Directive ( {
3938 exportAs : 'toggle' ,
4039 selector : '[igxToggle]' ,
41- standalone : true
40+ standalone : true ,
41+ host : {
42+ '[class.igx-toggle--hidden]' : 'hiddenClass' ,
43+ '[attr.aria-hidden]' : 'hiddenClass' ,
44+ '[class.igx-toggle--hidden-webkit]' : 'hiddenWebkitClass' ,
45+ '[class.igx-toggle]' : 'defaultClass'
46+ }
4247} )
4348export class IgxToggleDirective implements IToggleView , OnInit , OnDestroy {
4449 /**
@@ -163,13 +168,13 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
163168 /**
164169 * @hidden
165170 */
166- @HostBinding ( 'class.igx-toggle--hidden' )
167- @HostBinding ( 'attr.aria-hidden' )
168171 public get hiddenClass ( ) {
169172 return this . collapsed ;
170173 }
171174
172- @HostBinding ( 'class.igx-toggle--hidden-webkit' )
175+ /**
176+ * @hidden
177+ */
173178 public get hiddenWebkitClass ( ) {
174179 const isSafari = this . platform ?. isSafari ;
175180 const browserVersion = this . platform ?. browserVersion ;
@@ -180,7 +185,6 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
180185 /**
181186 * @hidden
182187 */
183- @HostBinding ( 'class.igx-toggle' )
184188 public get defaultClass ( ) {
185189 return ! this . collapsed ;
186190 }
@@ -228,6 +232,16 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
228232 }
229233
230234 this . _collapsed = false ;
235+
236+ // TODO: this is a workaround for the issue introduced by Angular's with Ivy renderer.
237+ // When calling detectChanges(), Angular marks the element for check, but does not update the classes
238+ // immediately, which causes the overlay to calculate incorrect dimensions of target element.
239+ // Overlay show should be called in the next tick to ensure the classes are updated and target element is measured correctly.
240+ // Note: across the codebase, each host binding should be checked and similar fix applied if needed!!!
241+ this . elementRef . nativeElement . className = this . elementRef . nativeElement . className . replace ( 'igx-toggle--hidden' , 'igx-toggle' ) ;
242+ this . elementRef . nativeElement . className = this . elementRef . nativeElement . className . replace ( 'igx-toggle--hidden-webkit' , 'igx-toggle' ) ;
243+ this . elementRef . nativeElement . removeAttribute ( 'aria-hidden' ) ;
244+
231245 this . cdr . detectChanges ( ) ;
232246
233247 if ( ! info ) {
0 commit comments