Skip to content

Commit c4d55ca

Browse files
authored
Use auto position strategy for grid toolbar dropdowns (#16429)
1 parent 46cd79c commit c4d55ca

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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';
1514
import { AbsoluteScrollStrategy } from '../../services/overlay/scroll/absolute-scroll-strategy';
1615
import { 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
})
3944
export 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) {

projects/igniteui-angular/src/lib/grids/toolbar/grid-toolbar.base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IgxColumnActionsComponent } from '../column-actions/column-actions.comp
99
import { IgxToggleDirective, ToggleViewCancelableEventArgs, ToggleViewEventArgs } from '../../directives/toggle/toggle.directive';
1010
import { HorizontalAlignment, OverlaySettings, VerticalAlignment } from '../../services/overlay/utilities';
1111
import { IgxToolbarToken } from './token';
12-
import { ConnectedPositioningStrategy } from '../../services/overlay/position/connected-positioning-strategy';
12+
import { AutoPositionStrategy } from '../../services/overlay/position/auto-position-strategy';
1313

1414
/* blazorInclude */
1515
/* blazorElement */
@@ -88,7 +88,7 @@ export abstract class BaseToolbarDirective implements OnDestroy {
8888
private $sub: Subscription;
8989

9090
private _overlaySettings: OverlaySettings = {
91-
positionStrategy: new ConnectedPositioningStrategy({
91+
positionStrategy: new AutoPositionStrategy({
9292
horizontalDirection: HorizontalAlignment.Left,
9393
horizontalStartPoint: HorizontalAlignment.Right,
9494
verticalDirection: VerticalAlignment.Bottom,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,18 @@ 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);
442+
if (openAnimation !== info.settings.positionStrategy.settings.openAnimation ||
443+
closeAnimation !== info.settings.positionStrategy.settings.closeAnimation){
444+
this.buildAnimationPlayers(info);
445+
}
440446
this.addModalClasses(info);
441447
if (info.settings.positionStrategy.settings.openAnimation) {
442448
// TODO: should we build players again. This was already done in attach!!!

0 commit comments

Comments
 (0)