Skip to content

Commit

Permalink
Fixed #10301 - Reimplement OverlayService
Browse files Browse the repository at this point in the history
  • Loading branch information
yigitfindikli committed Jun 30, 2021
1 parent 87eca54 commit 483348e
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 45 deletions.
13 changes: 10 additions & 3 deletions src/app/components/autocomplete/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {trigger,style,transition,animate,AnimationEvent} from '@angular/animatio
import {InputTextModule} from 'primeng/inputtext';
import {ButtonModule} from 'primeng/button';
import {RippleModule} from 'primeng/ripple';
import {SharedModule,PrimeTemplate, TranslationKeys, PrimeNGConfig} from 'primeng/api';
import {SharedModule,PrimeTemplate, TranslationKeys, PrimeNGConfig, OverlayService} from 'primeng/api';
import {DomHandler, ConnectedOverlayScrollHandler} from 'primeng/dom';
import {ObjectUtils, UniqueComponentId, ZIndexUtils} from 'primeng/utils';
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';
Expand Down Expand Up @@ -39,7 +39,7 @@ export const AUTOCOMPLETE_VALUE_ACCESSOR: any = {
</ul>
<i *ngIf="loading" class="p-autocomplete-loader pi pi-spinner pi-spin"></i><button #ddBtn type="button" pButton [icon]="dropdownIcon" class="p-autocomplete-dropdown" [disabled]="disabled" pRipple
(click)="handleDropdownClick($event)" *ngIf="dropdown" [attr.tabindex]="tabindex"></button>
<div #panel *ngIf="overlayVisible" [ngClass]="['p-autocomplete-panel p-component']" [style.max-height]="virtualScroll ? 'auto' : scrollHeight" [ngStyle]="panelStyle" [class]="panelStyleClass"
<div #panel *ngIf="overlayVisible" (click)="onOverlayClick($event)" [ngClass]="['p-autocomplete-panel p-component']" [style.max-height]="virtualScroll ? 'auto' : scrollHeight" [ngStyle]="panelStyle" [class]="panelStyleClass"
[@overlayAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" (@overlayAnimation.start)="onOverlayAnimationStart($event)" (@overlayAnimation.done)="onOverlayAnimationEnd($event)">
<ng-container *ngTemplateOutlet="headerTemplate"></ng-container>
<ul role="listbox" [attr.id]="listId" class="p-autocomplete-items" [ngClass]="{'p-autocomplete-virtualscroll': virtualScroll}">
Expand Down Expand Up @@ -294,7 +294,7 @@ export class AutoComplete implements AfterViewChecked,AfterContentInit,OnDestroy

virtualScrollSelectedIndex: number;

constructor(public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, public differs: IterableDiffers, public config: PrimeNGConfig) {
constructor(public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, public differs: IterableDiffers, public config: PrimeNGConfig, public overlayService: OverlayService) {
this.differ = differs.find([]).create(null);
this.listId = UniqueComponentId() + '_list';
}
Expand Down Expand Up @@ -566,6 +566,13 @@ export class AutoComplete implements AfterViewChecked,AfterContentInit,OnDestroy
}
}

onOverlayClick(event) {
this.overlayService.add({
originalEvent: event,
target: this.el.nativeElement
});
}

appendOverlay() {
if (this.appendTo) {
if (this.appendTo === 'body')
Expand Down
13 changes: 10 additions & 3 deletions src/app/components/calendar/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {CommonModule} from '@angular/common';
import {ButtonModule} from 'primeng/button';
import {RippleModule} from 'primeng/ripple';
import {DomHandler, ConnectedOverlayScrollHandler} from 'primeng/dom';
import {SharedModule,PrimeTemplate,PrimeNGConfig,TranslationKeys} from 'primeng/api';
import {SharedModule,PrimeTemplate,PrimeNGConfig,TranslationKeys, OverlayService} from 'primeng/api';
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';
import {Subscription} from 'rxjs';
import {ZIndexUtils} from 'primeng/utils';
Expand Down Expand Up @@ -44,7 +44,7 @@ export interface LocaleSettings {
'p-disabled':disabled,'p-datepicker-timeonly':timeOnly,'p-datepicker-multiple-month': this.numberOfMonths > 1, 'p-datepicker-monthpicker': (view === 'month'), 'p-datepicker-touch-ui': touchUI}"
[@overlayAnimation]="touchUI ? {value: 'visibleTouchUI', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}:
{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}"
[@.disabled]="inline === true" (@overlayAnimation.start)="onOverlayAnimationStart($event)" (@overlayAnimation.done)="onOverlayAnimationDone($event)" *ngIf="inline || overlayVisible">
[@.disabled]="inline === true" (@overlayAnimation.start)="onOverlayAnimationStart($event)" (@overlayAnimation.done)="onOverlayAnimationDone($event)" (click)="onOverlayClick($event)" *ngIf="inline || overlayVisible">
<ng-content select="p-header"></ng-content>
<ng-container *ngTemplateOutlet="headerTemplate"></ng-container>
<ng-container *ngIf="!timeOnly">
Expand Down Expand Up @@ -544,7 +544,7 @@ export class Calendar implements OnInit,OnDestroy,ControlValueAccessor {
console.warn("Locale property has no effect, use new i18n API instead.");
}

constructor(public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, private zone: NgZone, private config: PrimeNGConfig) {}
constructor(public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, private zone: NgZone, private config: PrimeNGConfig, public overlayService: OverlayService) {}

ngOnInit() {
const date = this.defaultDate||new Date();
Expand Down Expand Up @@ -1225,6 +1225,13 @@ export class Calendar implements OnInit,OnDestroy,ControlValueAccessor {
}
}

onOverlayClick(event) {
this.overlayService.add({
originalEvent: event,
target: this.el.nativeElement
});
}

onPrevButtonClick(event) {
this.navigationState = {backward: true, button: true};
this.navBackward(event);
Expand Down
13 changes: 10 additions & 3 deletions src/app/components/cascadeselect/cascadeselect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NgModule, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, TemplateRef, ContentChildren, QueryList, ElementRef, Output, EventEmitter, ViewChild, forwardRef, ChangeDetectorRef, Renderer2, OnDestroy, OnInit, AfterContentInit} from '@angular/core';
import { CommonModule } from '@angular/common';
import { SharedModule, PrimeTemplate, PrimeNGConfig } from 'primeng/api';
import { SharedModule, PrimeTemplate, PrimeNGConfig, OverlayService } from 'primeng/api';
import { ObjectUtils, ZIndexUtils } from 'primeng/utils';
import { DomHandler } from 'primeng/dom';
import { trigger,style,transition,animate,AnimationEvent} from '@angular/animations';
Expand Down Expand Up @@ -241,7 +241,7 @@ export class CascadeSelectSub implements OnInit {
<div class="p-cascadeselect-trigger" role="button" aria-haspopup="listbox" [attr.aria-expanded]="overlayVisible">
<span class="p-cascadeselect-trigger-icon pi pi-chevron-down"></span>
</div>
<div class="p-cascadeselect-panel p-component" *ngIf="overlayVisible"
<div class="p-cascadeselect-panel p-component" *ngIf="overlayVisible" (click)="onOverlayClick($event)"
[@overlayAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" (@overlayAnimation.start)="onOverlayAnimationStart($event)" (@overlayAnimation.done)="onOverlayAnimationDone($event)">
<div class="p-cascadeselect-items-wrapper">
<p-cascadeSelectSub [options]="options" [selectionPath]="selectionPath" class="p-cascadeselect-items"
Expand Down Expand Up @@ -355,7 +355,7 @@ export class CascadeSelect implements OnInit, AfterContentInit, OnDestroy {

onModelTouched: Function = () => {};

constructor(private el: ElementRef, private cd: ChangeDetectorRef, private config: PrimeNGConfig) { }
constructor(private el: ElementRef, private cd: ChangeDetectorRef, private config: PrimeNGConfig, public overlayService: OverlayService) { }

ngOnInit() {
this.updateSelectionPath();
Expand Down Expand Up @@ -477,6 +477,13 @@ export class CascadeSelect implements OnInit, AfterContentInit, OnDestroy {
this.focused = false;
}

onOverlayClick(event) {
this.overlayService.add({
originalEvent: event,
target: this.el.nativeElement
});
}

onOverlayAnimationStart(event: AnimationEvent) {
switch (event.toState) {
case 'visible':
Expand Down
13 changes: 9 additions & 4 deletions src/app/components/colorpicker/colorpicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { trigger, state, style, transition, animate, AnimationEvent } from '@ang
import { CommonModule } from '@angular/common';
import { DomHandler, ConnectedOverlayScrollHandler } from 'primeng/dom';
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';
import { PrimeNGConfig } from 'primeng/api';
import { OverlayService, PrimeNGConfig } from 'primeng/api';
import { ZIndexUtils } from 'primeng/utils';

export const COLORPICKER_VALUE_ACCESSOR: any = {
Expand All @@ -19,7 +19,7 @@ export const COLORPICKER_VALUE_ACCESSOR: any = {
<input #input type="text" *ngIf="!inline" class="p-colorpicker-preview p-inputtext" readonly="readonly" [ngClass]="{'p-disabled': disabled}"
(focus)="onInputFocus()" (click)="onInputClick()" (keydown)="onInputKeydown($event)" [attr.id]="inputId" [attr.tabindex]="tabindex" [disabled]="disabled"
[style.backgroundColor]="inputBgColor">
<div *ngIf="inline || overlayVisible" [ngClass]="{'p-colorpicker-panel': true, 'p-colorpicker-overlay-panel':!inline, 'p-disabled': disabled}" (click)="onPanelClick()"
<div *ngIf="inline || overlayVisible" [ngClass]="{'p-colorpicker-panel': true, 'p-colorpicker-overlay-panel':!inline, 'p-disabled': disabled}" (click)="onOverlayClick($event)"
[@overlayAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" [@.disabled]="inline === true"
(@overlayAnimation.start)="onOverlayAnimationStart($event)" (@overlayAnimation.done)="onOverlayAnimationEnd($event)">
<div class="p-colorpicker-content">
Expand Down Expand Up @@ -129,7 +129,7 @@ export class ColorPicker implements ControlValueAccessor, OnDestroy {

hueHandleViewChild: ElementRef;

constructor(public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, public config: PrimeNGConfig) {}
constructor(public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, public config: PrimeNGConfig, public overlayService: OverlayService) {}

@ViewChild('colorSelector') set colorSelector(element: ElementRef) {
this.colorSelectorViewChild = element;
Expand Down Expand Up @@ -418,7 +418,12 @@ export class ColorPicker implements ControlValueAccessor, OnDestroy {
}
}

onPanelClick() {
onOverlayClick(event) {
this.overlayService.add({
originalEvent: event,
target: this.el.nativeElement
});

this.selfClick = true;
}

Expand Down
13 changes: 10 additions & 3 deletions src/app/components/confirmpopup/confirmpopup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {NgModule ,Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, ChangeDetectorRef, OnDestroy, Input, EventEmitter, Renderer2} from '@angular/core';
import {CommonModule} from '@angular/common';
import {Confirmation, ConfirmationService, PrimeNGConfig, TranslationKeys} from 'primeng/api';
import {Confirmation, ConfirmationService, OverlayService, PrimeNGConfig, TranslationKeys} from 'primeng/api';
import {Subscription} from 'rxjs';
import {ButtonModule} from 'primeng/button';
import {ZIndexUtils} from 'primeng/utils';
Expand All @@ -10,7 +10,7 @@ import {DomHandler, ConnectedOverlayScrollHandler} from 'primeng/dom';
@Component({
selector: 'p-confirmPopup',
template: `
<div *ngIf="visible" [ngClass]="'p-confirm-popup p-component'" [ngStyle]="style" [class]="styleClass"
<div *ngIf="visible" [ngClass]="'p-confirm-popup p-component'" [ngStyle]="style" [class]="styleClass" (click)="onOverlayClick($event)"
[@animation]="{value: 'open', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}"
(@animation.start)="onAnimationStart($event)" (@animation.done)="onAnimationEnd($event)">
<div #content class="p-confirm-popup-content">
Expand Down Expand Up @@ -81,7 +81,7 @@ export class ConfirmPopup implements OnDestroy {
this.cd.markForCheck();
}

constructor(public el: ElementRef, private confirmationService: ConfirmationService, public renderer: Renderer2, private cd: ChangeDetectorRef, public config: PrimeNGConfig) {
constructor(public el: ElementRef, private confirmationService: ConfirmationService, public renderer: Renderer2, private cd: ChangeDetectorRef, public config: PrimeNGConfig, public overlayService: OverlayService) {
this.subscription = this.confirmationService.requireConfirmation$.subscribe(confirmation => {
if (!confirmation) {
this.hide();
Expand Down Expand Up @@ -163,6 +163,13 @@ export class ConfirmPopup implements OnDestroy {
this.hide();
}

onOverlayClick(event) {
this.overlayService.add({
originalEvent: event,
target: this.el.nativeElement
});
}

bindListeners() {
this.bindDocumentClickListener();
this.bindDocumentResizeListener();
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView

@Input() editable: boolean;

@Input() appendTo: any;
@Input() appendTo: any = "body";

@Input() tabindex: number;

Expand Down Expand Up @@ -611,7 +611,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
this.overlayService.add({
originalEvent: event,
target: this.el.nativeElement
})
});
}

isInputClick(event): boolean {
Expand Down
15 changes: 12 additions & 3 deletions src/app/components/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {NgModule,Component,ElementRef,OnDestroy,Input,Output,EventEmitter,Render
import {trigger,state,style,transition,animate,AnimationEvent} from '@angular/animations';
import {CommonModule} from '@angular/common';
import {DomHandler, ConnectedOverlayScrollHandler} from 'primeng/dom';
import {MenuItem, PrimeNGConfig} from 'primeng/api';
import {MenuItem, OverlayService, PrimeNGConfig} from 'primeng/api';
import {ZIndexUtils} from 'primeng/utils';
import {RouterModule} from '@angular/router';
import {RippleModule} from 'primeng/ripple';
Expand Down Expand Up @@ -42,7 +42,7 @@ export class MenuItemContent {
selector: 'p-menu',
template: `
<div #container [ngClass]="{'p-menu p-component': true, 'p-menu-overlay': popup}"
[class]="styleClass" [ngStyle]="style" (click)="preventDocumentDefault=true" *ngIf="!popup || visible"
[class]="styleClass" [ngStyle]="style" (click)="preventDocumentDefault=true" *ngIf="!popup || visible" (click)="onOverlayClick($event)"
[@overlayAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" [@.disabled]="popup !== true" (@overlayAnimation.start)="onOverlayAnimationStart($event)" (@overlayAnimation.done)="onOverlayAnimationEnd($event)">
<ul class="p-menu-list p-reset">
<ng-template ngFor let-submenu [ngForOf]="model" *ngIf="hasSubMenu()">
Expand Down Expand Up @@ -120,7 +120,7 @@ export class Menu implements OnDestroy {

relativeAlign: boolean;

constructor(public el: ElementRef, public renderer: Renderer2, private cd: ChangeDetectorRef, public config: PrimeNGConfig) {}
constructor(public el: ElementRef, public renderer: Renderer2, private cd: ChangeDetectorRef, public config: PrimeNGConfig, public overlayService: OverlayService) {}

toggle(event) {
if (this.visible)
Expand Down Expand Up @@ -231,6 +231,15 @@ export class Menu implements OnDestroy {
}
}

onOverlayClick(event) {
if (this.popup) {
this.overlayService.add({
originalEvent: event,
target: this.el.nativeElement
});
}
}

bindDocumentClickListener() {
if (!this.documentClickListener) {
const documentTarget: any = this.el ? this.el.nativeElement.ownerDocument : 'document';
Expand Down
13 changes: 10 additions & 3 deletions src/app/components/multiselect/multiselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { trigger,style,transition,animate,AnimationEvent} from '@angular/animati
import { CommonModule } from '@angular/common';
import { DomHandler, ConnectedOverlayScrollHandler } from 'primeng/dom';
import { ObjectUtils, ZIndexUtils } from 'primeng/utils';
import { SharedModule, PrimeTemplate, Footer, Header, FilterService, PrimeNGConfig, TranslationKeys } from 'primeng/api';
import { SharedModule, PrimeTemplate, Footer, Header, FilterService, PrimeNGConfig, TranslationKeys, OverlayService } from 'primeng/api';
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';
import { ScrollingModule } from '@angular/cdk/scrolling';
import { TooltipModule } from 'primeng/tooltip';
Expand Down Expand Up @@ -99,7 +99,7 @@ export class MultiSelectItem {
<span class="p-multiselect-trigger-icon" [ngClass]="dropdownIcon"></span>
</div>
<div *ngIf="overlayVisible" [ngClass]="['p-multiselect-panel p-component']" [@overlayAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" (@overlayAnimation.start)="onOverlayAnimationStart($event)"onOverlayAnimationEnd
(@overlayAnimation.done)="onOverlayAnimationEnd($event)" [ngStyle]="panelStyle" [class]="panelStyleClass" (keydown)="onKeydown($event)">
(@overlayAnimation.done)="onOverlayAnimationEnd($event)" [ngStyle]="panelStyle" [class]="panelStyleClass" (keydown)="onKeydown($event)" (click)="onOverlayClick($event)" >
<div class="p-multiselect-header" *ngIf="showHeader">
<ng-content select="p-header"></ng-content>
<ng-container *ngTemplateOutlet="headerTemplate"></ng-container>
Expand Down Expand Up @@ -402,7 +402,7 @@ export class MultiSelect implements OnInit,AfterViewInit,AfterContentInit,AfterV

preventModelTouched: boolean;

constructor(public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, public filterService: FilterService, public config: PrimeNGConfig) {}
constructor(public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, public filterService: FilterService, public config: PrimeNGConfig, public overlayService: OverlayService) {}

ngOnInit() {
this.updateLabel();
Expand Down Expand Up @@ -658,6 +658,13 @@ export class MultiSelect implements OnInit,AfterViewInit,AfterContentInit,AfterV
}
}

onOverlayClick(event) {
this.overlayService.add({
originalEvent: event,
target: this.el.nativeElement
});
}

onOverlayAnimationStart(event: AnimationEvent) {
switch (event.toState) {
case 'visible':
Expand Down
Loading

0 comments on commit 483348e

Please sign in to comment.