-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module:menu dropdown): refactor menu dropdown & add test & add d…
…oc (#990) feat(module:menu dropdown): refactor menu dropdown & add test & add doc
- Loading branch information
Showing
63 changed files
with
2,126 additions
and
507 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
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
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 @@ | ||
export * from './public-api'; |
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,3 @@ | ||
export * from './nz-button.component'; | ||
export * from './nz-button-group.component'; | ||
export * from './nz-button.module'; |
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,42 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { | ||
createFakeEvent, | ||
createKeyboardEvent, | ||
createMouseEvent, | ||
createTouchEvent | ||
} from './event-objects'; | ||
|
||
/** Utility to dispatch any event on a Node. */ | ||
export function dispatchEvent(node: Node | Window, event: Event): Event { | ||
node.dispatchEvent(event); | ||
return event; | ||
} | ||
|
||
/** Shorthand to dispatch a fake event on a specified node. */ | ||
export function dispatchFakeEvent(node: Node | Window, type: string, canBubble?: boolean): Event { | ||
return dispatchEvent(node, createFakeEvent(type, canBubble)); | ||
} | ||
|
||
/** Shorthand to dispatch a keyboard event with a specified key code. */ | ||
export function dispatchKeyboardEvent(node: Node, type: string, keyCode: number, target?: Element): | ||
KeyboardEvent { | ||
return dispatchEvent(node, createKeyboardEvent(type, keyCode, target)) as KeyboardEvent; | ||
} | ||
|
||
/** Shorthand to dispatch a mouse event on the specified coordinates. */ | ||
export function dispatchMouseEvent(node: Node, type: string, x = 0, y = 0, | ||
event = createMouseEvent(type, x, y)): MouseEvent { | ||
return dispatchEvent(node, event) as MouseEvent; | ||
} | ||
|
||
/** Shorthand to dispatch a touch event on the specified coordinates. */ | ||
export function dispatchTouchEvent(node: Node, type: string, x = 0, y = 0) { | ||
return dispatchEvent(node, createTouchEvent(type, x, y)); | ||
} |
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,81 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/** Creates a browser MouseEvent with the specified options. */ | ||
export function createMouseEvent(type: string, x = 0, y = 0) { | ||
const event = document.createEvent('MouseEvent'); | ||
|
||
event.initMouseEvent(type, | ||
false, /* canBubble */ | ||
false, /* cancelable */ | ||
window, /* view */ | ||
0, /* detail */ | ||
x, /* screenX */ | ||
y, /* screenY */ | ||
x, /* clientX */ | ||
y, /* clientY */ | ||
false, /* ctrlKey */ | ||
false, /* altKey */ | ||
false, /* shiftKey */ | ||
false, /* metaKey */ | ||
0, /* button */ | ||
null /* relatedTarget */); | ||
|
||
return event; | ||
} | ||
|
||
/** Creates a browser TouchEvent with the specified pointer coordinates. */ | ||
export function createTouchEvent(type: string, pageX = 0, pageY = 0) { | ||
// In favor of creating events that work for most of the browsers, the event is created | ||
// as a basic UI Event. The necessary details for the event will be set manually. | ||
const event = document.createEvent('UIEvent'); | ||
const touchDetails = {pageX, pageY}; | ||
|
||
event.initUIEvent(type, true, true, window, 0); | ||
|
||
// Most of the browsers don't have a "initTouchEvent" method that can be used to define | ||
// the touch details. | ||
Object.defineProperties(event, { | ||
touches: {value: [touchDetails]} | ||
}); | ||
|
||
return event; | ||
} | ||
|
||
/** Dispatches a keydown event from an element. */ | ||
export function createKeyboardEvent(type: string, keyCode: number, target?: Element, key?: string) { | ||
let event = document.createEvent('KeyboardEvent') as any; | ||
// Firefox does not support `initKeyboardEvent`, but supports `initKeyEvent`. | ||
let initEventFn = (event.initKeyEvent || event.initKeyboardEvent).bind(event); | ||
let originalPreventDefault = event.preventDefault; | ||
|
||
initEventFn(type, true, true, window, 0, 0, 0, 0, 0, keyCode); | ||
|
||
// Webkit Browsers don't set the keyCode when calling the init function. | ||
// See related bug https://bugs.webkit.org/show_bug.cgi?id=16735 | ||
Object.defineProperties(event, { | ||
keyCode: { get: () => keyCode }, | ||
key: { get: () => key }, | ||
target: { get: () => target } | ||
}); | ||
|
||
// IE won't set `defaultPrevented` on synthetic events so we need to do it manually. | ||
event.preventDefault = function() { | ||
Object.defineProperty(event, 'defaultPrevented', { get: () => true }); | ||
return originalPreventDefault.apply(this, arguments); | ||
}; | ||
|
||
return event; | ||
} | ||
|
||
/** Creates a fake event object with any desired event type. */ | ||
export function createFakeEvent(type: string, canBubble = true, cancelable = true) { | ||
const event = document.createEvent('Event'); | ||
event.initEvent(type, canBubble, cancelable); | ||
return event; | ||
} |
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,24 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/** @docs-private */ | ||
export class FakeViewportRuler { | ||
getViewportRect() { | ||
return { | ||
left: 0, top: 0, width: 1014, height: 686, bottom: 686, right: 1014 | ||
}; | ||
} | ||
|
||
getViewportSize() { | ||
return {width: 1014, height: 686}; | ||
} | ||
|
||
getViewportScrollPosition() { | ||
return {top: 0, left: 0}; | ||
} | ||
} |
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,11 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
|
||
|
||
export * from './public-api'; |
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,38 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {EventEmitter, Injectable, NgZone} from '@angular/core'; | ||
|
||
|
||
/** | ||
* Mock synchronous NgZone implementation that can be used | ||
* to flush out `onStable` subscriptions in tests. | ||
* | ||
* via: https://github.com/angular/angular/blob/master/packages/core/testing/src/ng_zone_mock.ts | ||
* @docs-private | ||
*/ | ||
@Injectable() | ||
export class MockNgZone extends NgZone { | ||
onStable: EventEmitter<any> = new EventEmitter(false); | ||
|
||
constructor() { | ||
super({enableLongStackTrace: false}); | ||
} | ||
|
||
run(fn: Function): any { | ||
return fn(); | ||
} | ||
|
||
runOutsideAngular(fn: Function): any { | ||
return fn(); | ||
} | ||
|
||
simulateZoneExit(): void { | ||
this.onStable.emit(null); | ||
} | ||
} |
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,14 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
export * from './dispatch-events'; | ||
export * from './event-objects'; | ||
export * from './type-in-element'; | ||
export * from './wrapped-error-message'; | ||
export * from './fake-viewport-ruler'; | ||
export * from './mock-ng-zone'; |
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,21 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {dispatchFakeEvent} from './dispatch-events'; | ||
|
||
/** | ||
* Focuses an input, sets its value and dispatches | ||
* the `input` event, simulating the user typing. | ||
* @param value Value to be set on the input. | ||
* @param element Element onto which to set the value. | ||
*/ | ||
export function typeInElement(value: string, element: HTMLInputElement) { | ||
element.focus(); | ||
element.value = value; | ||
dispatchFakeEvent(element, 'input'); | ||
} |
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,16 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/** | ||
* Gets a RegExp used to detect an angular wrapped error message. | ||
* See https://github.com/angular/angular/issues/8348 | ||
*/ | ||
export function wrappedErrorMessage(e: Error) { | ||
const escapedMessage = e.message.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); | ||
return new RegExp(escapedMessage); | ||
} |
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
Oops, something went wrong.