Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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,16 +1,19 @@
import {
afterNextRender,
ChangeDetectorRef,
Directive,
ElementRef,
EventEmitter,
HostBinding,
HostListener,
inject,
Inject,
Injector,
Input,
OnDestroy,
OnInit,
Optional,
Output
Output,
runInInjectionContext
} from '@angular/core';
import { AbsoluteScrollStrategy } from '../../services/overlay/scroll/absolute-scroll-strategy';
import { CancelableBrowserEventArgs, IBaseEventArgs, PlatformUtil } from '../../core/utils';
Expand All @@ -34,7 +37,13 @@ export interface ToggleViewCancelableEventArgs extends ToggleViewEventArgs, Canc
@Directive({
exportAs: 'toggle',
selector: '[igxToggle]',
standalone: true
standalone: true,
host: {
'[class.igx-toggle--hidden]': 'hiddenClass',
'[attr.aria-hidden]': 'hiddenClass',
'[class.igx-toggle--hidden-webkit]': 'hiddenWebkitClass',
'[class.igx-toggle]': 'defaultClass'
}
})
export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
/**
Expand Down Expand Up @@ -159,13 +168,13 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
/**
* @hidden
*/
@HostBinding('class.igx-toggle--hidden')
@HostBinding('attr.aria-hidden')
public get hiddenClass() {
return this.collapsed;
}

@HostBinding('class.igx-toggle--hidden-webkit')
/**
* @hidden
*/
public get hiddenWebkitClass() {
const isSafari = this.platform?.isSafari;
const browserVersion = this.platform?.browserVersion;
Expand All @@ -176,7 +185,6 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
/**
* @hidden
*/
@HostBinding('class.igx-toggle')
public get defaultClass() {
return !this.collapsed;
}
Expand All @@ -193,6 +201,7 @@ 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 @@ -224,25 +233,28 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
}

this._collapsed = false;
this.cdr.detectChanges();

if (!info) {
this.unsubscribe();
this.subscribe();
this._overlayId = this.overlayService.attach(this.elementRef, overlaySettings);
}
runInInjectionContext(this._injector, () =>{
afterNextRender(() => {
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IgxColumnActionsComponent } from '../column-actions/column-actions.comp
import { IgxToggleDirective, ToggleViewCancelableEventArgs, ToggleViewEventArgs } from '../../directives/toggle/toggle.directive';
import { HorizontalAlignment, OverlaySettings, VerticalAlignment } from '../../services/overlay/utilities';
import { IgxToolbarToken } from './token';
import { ConnectedPositioningStrategy } from '../../services/overlay/position/connected-positioning-strategy';
import { AutoPositionStrategy } from '../../services/overlay/position/auto-position-strategy';

/* blazorInclude */
/* blazorElement */
Expand Down Expand Up @@ -88,7 +88,7 @@ export abstract class BaseToolbarDirective implements OnDestroy {
private $sub: Subscription;

private _overlaySettings: OverlaySettings = {
positionStrategy: new ConnectedPositioningStrategy({
positionStrategy: new AutoPositionStrategy({
horizontalDirection: HorizontalAlignment.Left,
horizontalStartPoint: HorizontalAlignment.Right,
verticalDirection: VerticalAlignment.Bottom,
Expand Down
Loading