This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NG] Datagrid: Fix performance issue for action overflow
We now properly add the click listener on the whole document only when the action overflow menu is open. Fixes #1111. Signed-off-by: Eudes Petonnet-Vincent <[email protected]>
- Loading branch information
Showing
7 changed files
with
151 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,4 +78,4 @@ export class DatagridSelectionDemo { | |
this.cleanUp(); | ||
this.toAdd = this.selected.slice(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright (c) 2016 VMware, Inc. All Rights Reserved. | ||
* This software is released under MIT license. | ||
* The full license information can be found in LICENSE in the root directory of this project. | ||
*/ | ||
import { Type } from "@angular/core"; | ||
import {OutsideClick} from "./outside-click"; | ||
|
||
export * from "./outside-click"; | ||
|
||
export const OUSTIDE_CLICK_DIRECTIVES: Type<any>[] = [ | ||
OutsideClick | ||
]; |
15 changes: 15 additions & 0 deletions
15
src/clarity-angular/utils/outside-click/outside-click.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Copyright (c) 2016-2017 VMware, Inc. All Rights Reserved. | ||
* This software is released under MIT license. | ||
* The full license information can be found in LICENSE in the root directory of this project. | ||
*/ | ||
import { NgModule } from "@angular/core"; | ||
import { CommonModule } from "@angular/common"; | ||
import {OUSTIDE_CLICK_DIRECTIVES} from "./index"; | ||
|
||
@NgModule({ | ||
imports: [CommonModule], | ||
declarations: [OUSTIDE_CLICK_DIRECTIVES], | ||
exports: [OUSTIDE_CLICK_DIRECTIVES] | ||
}) | ||
export class ClrOutsideClickModule {} |
72 changes: 72 additions & 0 deletions
72
src/clarity-angular/utils/outside-click/outside-click.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2016 VMware, Inc. All Rights Reserved. | ||
* This software is released under MIT license. | ||
* The full license information can be found in LICENSE in the root directory of this project. | ||
*/ | ||
import {Component} from "@angular/core"; | ||
import {TestBed} from "@angular/core/testing"; | ||
import {By} from "@angular/platform-browser"; | ||
import {OutsideClick} from "./outside-click"; | ||
|
||
describe("Loading directive", function() { | ||
beforeEach(function () { | ||
TestBed.configureTestingModule({ | ||
declarations: [OutsideClick, FullTest] | ||
}); | ||
this.fixture = TestBed.createComponent(FullTest); | ||
this.fixture.detectChanges(); | ||
this.testComponent = this.fixture.componentInstance; | ||
this.host = this.fixture.debugElement.query(By.css(".host")).nativeElement; | ||
this.button = this.fixture.debugElement.query(By.css("button")).nativeElement; | ||
this.outside = this.fixture.debugElement.query(By.css(".outside")).nativeElement; | ||
}); | ||
|
||
afterEach(function() { | ||
this.fixture.destroy(); | ||
}); | ||
|
||
it("emits clicks outside of the host", function () { | ||
expect(this.testComponent.nbClicks).toBe(0); | ||
this.outside.click(); | ||
expect(this.testComponent.nbClicks).toBe(1); | ||
this.outside.click(); | ||
expect(this.testComponent.nbClicks).toBe(2); | ||
}); | ||
|
||
it("ignores clicks inside of the host", function () { | ||
expect(this.testComponent.nbClicks).toBe(0); | ||
this.host.click(); | ||
expect(this.testComponent.nbClicks).toBe(0); | ||
this.button.click(); | ||
expect(this.testComponent.nbClicks).toBe(0); | ||
}); | ||
|
||
it("offers a strict input to only ignore clicks that happen exactly on the host", function () { | ||
this.testComponent.strict = true; | ||
this.fixture.detectChanges(); | ||
expect(this.testComponent.nbClicks).toBe(0); | ||
this.host.click(); | ||
expect(this.testComponent.nbClicks).toBe(0); | ||
this.button.click(); | ||
expect(this.testComponent.nbClicks).toBe(1); | ||
}); | ||
}); | ||
|
||
|
||
@Component({ | ||
template: ` | ||
<p class="outside">Hello World</p> | ||
<p class="host" (clrOutsideClick)="inc()" [clrStrict]="strict"> | ||
<button>Button</button> | ||
</p> | ||
` | ||
}) | ||
class FullTest { | ||
public strict = false; | ||
public nbClicks = 0; | ||
|
||
inc() { | ||
this.nbClicks++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {Directive, Output, EventEmitter, HostListener, ElementRef, Input} from "@angular/core"; | ||
|
||
@Directive({ | ||
selector: "[clrOutsideClick]" | ||
}) | ||
export class OutsideClick { | ||
constructor(private el: ElementRef) {} | ||
|
||
@Input("clrStrict") strict = false; | ||
|
||
@Output("clrOutsideClick") outsideClick = new EventEmitter<any>(false); | ||
|
||
@HostListener("document:click", ["$event"]) | ||
documentClick(event: MouseEvent) { | ||
let target = event.target; //Get the element in the DOM on which the mouse was clicked | ||
let host = this.el.nativeElement; //Get the current actionMenu native HTML element | ||
|
||
if (target === host) { | ||
return; | ||
} | ||
if (!this.strict && host.contains(target)) { | ||
return; | ||
} | ||
this.outsideClick.emit(event); | ||
} | ||
} |