Skip to content
This repository was archived by the owner on May 15, 2019. It is now read-only.

Commit 1139efa

Browse files
Eyal Hakimbenjaminforras
authored andcommitted
move element-closest to polyfills.ts
fix Array declerations syntax fix strange bug on build (edcarroll#357) fix optional param
1 parent aa0242e commit 1139efa

File tree

5 files changed

+103
-96
lines changed

5 files changed

+103
-96
lines changed

demo/src/app/components/sidebar/sidebar.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import {Component, EventEmitter, HostListener, isDevMode, Output} from "@angular/core";
2-
// Polyfill for IE
3-
import "element-closest";
1+
import { Component, HostBinding, Output, EventEmitter, HostListener, isDevMode } from "@angular/core";
42

53
interface IAugmentedElement extends Element {
64
closest(selector:string):IAugmentedElement;

demo/src/polyfills.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,5 @@ import "zone.js/dist/zone"; // Included with Angular CLI.
7070
/***************************************************************************************************
7171
* APPLICATION IMPORTS
7272
*/
73+
import "core-js/es7/reflect";
74+
import "element-closest";

src/modules/datepicker/helpers/date-fns.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { IDatepickerLocaleValues } from "../../../behaviors/localization/interna
22
import { format, parse } from "date-fns";
33
import * as defaultLocale from "date-fns/locale/en-US";
44

5+
<<<<<<< HEAD
56
interface IDateFnsLocaleValues {
67
[name: string]: string[];
78
}
@@ -11,6 +12,11 @@ interface IDateFnsHelperOptions {
1112
}
1213

1314
type DateFnsHelper<U, T> = (value: U, options: IDateFnsHelperOptions) => T;
15+
=======
16+
interface IDateFnsLocaleValues { [name:string]:string[]; }
17+
interface IDateFnsHelperOptions { type:string; }
18+
type DateFnsHelper<U, T> = (value:U, options:IDateFnsHelperOptions) => T;
19+
>>>>>>> 4c27b73... move element-closest to polyfills.ts
1420
type DateFnsWeekStartsOn = 0 | 1 | 2 | 3 | 4 | 5 | 6;
1521

1622
interface IDateFnsCustomLocale {

src/modules/dropdown/directives/dropdown-menu.ts

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,34 @@ import { DropdownAutoCloseType, DropdownService } from "../services/dropdown.ser
1919
import "element-closest";
2020

2121
@Directive({
22-
// We must attach to every '.item' as Angular doesn't support > selectors.
23-
selector: ".item"
24-
})
22+
// We must attach to every '.item' as Angular doesn't support > selectors.
23+
selector: ".item"
24+
})
2525
export class SuiDropdownMenuItem {
2626
// Stores the class name used for a 'selected' item.
27-
public selectedClass: string;
27+
public selectedClass:string;
2828
@ContentChild(forwardRef(() => SuiDropdownMenu))
29-
public childDropdownMenu: SuiDropdownMenu;
29+
public childDropdownMenu:SuiDropdownMenu;
3030

31-
constructor(private _renderer: Renderer2, public element: ElementRef) {
31+
constructor(private _renderer:Renderer2, public element:ElementRef) {
3232
this.isSelected = false;
3333

3434
this.selectedClass = "selected";
3535
}
3636

37-
public get isDisabled(): boolean {
37+
public get isDisabled():boolean {
3838
// We must use nativeElement as Angular doesn't have a way of reading class information.
3939
const element = this.element.nativeElement as Element;
4040
return element.classList.contains("disabled");
4141
}
4242

43-
private _isSelected: boolean;
43+
private _isSelected:boolean;
4444

45-
public get isSelected(): boolean {
45+
public get isSelected():boolean {
4646
return this._isSelected;
4747
}
4848

49-
public set isSelected(value: boolean) {
49+
public set isSelected(value:boolean) {
5050
// Renderer is used to enable a dynamic class name.
5151
if (value) {
5252
this._renderer.addClass(this.element.nativeElement, this.selectedClass);
@@ -55,38 +55,38 @@ export class SuiDropdownMenuItem {
5555
}
5656
}
5757

58-
public get hasChildDropdown(): boolean {
58+
public get hasChildDropdown():boolean {
5959
return !!this.childDropdownMenu;
6060
}
6161

62-
public performClick(): void {
62+
public performClick():void {
6363
// Using directly because Renderer2 doesn't have invokeElementMethod method anymore.
6464
this.element.nativeElement.click();
6565
}
6666
}
6767

6868
@Directive({
69-
selector: "[suiDropdownMenu]"
70-
})
69+
selector: "[suiDropdownMenu]"
70+
})
7171
export class SuiDropdownMenu extends SuiTransition implements AfterContentInit, OnDestroy {
7272
@Input()
73-
public menuTransition: string;
73+
public menuTransition:string;
7474
@Input()
75-
public menuTransitionDuration: number;
75+
public menuTransitionDuration:number;
7676
// Selected items lower in the stack are necessarily the parent of the item one higher.
77-
public selectedItems: SuiDropdownMenuItem[];
77+
public selectedItems:SuiDropdownMenuItem[];
7878
// Sets whether or not to automatically select the 1st item when the dropdown is opened.
7979
@Input()
80-
public menuAutoSelectFirst: boolean;
80+
public menuAutoSelectFirst:boolean;
8181
@Input()
82-
public menuSelectedItemClass: string;
83-
private _transitionController: TransitionController;
82+
public menuSelectedItemClass:string;
83+
private _transitionController:TransitionController;
8484
@ContentChildren(SuiDropdownMenuItem)
85-
private _itemsQueryInternal: QueryList<SuiDropdownMenuItem>;
86-
private _itemsQueryOverride: QueryList<SuiDropdownMenuItem>;
87-
private _parentKeyDownListener: () => void;
85+
private _itemsQueryInternal:QueryList<SuiDropdownMenuItem>;
86+
private _itemsQueryOverride:QueryList<SuiDropdownMenuItem>;
87+
private _parentKeyDownListener:() => void;
8888

89-
constructor(renderer: Renderer2, element: ElementRef, changeDetector: ChangeDetectorRef) {
89+
constructor(renderer:Renderer2, element:ElementRef, changeDetector:ChangeDetectorRef) {
9090
super(renderer, element, changeDetector);
9191

9292
// Initialise transition functionality.
@@ -104,19 +104,19 @@ export class SuiDropdownMenu extends SuiTransition implements AfterContentInit,
104104
};
105105
}
106106

107-
private _service: DropdownService;
107+
private _service:DropdownService;
108108

109-
public get service(): DropdownService {
109+
public get service():DropdownService {
110110
return this._service;
111111
}
112112

113113
// Stack that keeps track of the currently selected item.
114114

115-
public set service(value: DropdownService) {
115+
public set service(value:DropdownService) {
116116
this._service = value;
117117

118118
let previousIsOpen = this._service.isOpen;
119-
this._service.isOpenChange.subscribe((isOpen: boolean) => {
119+
this._service.isOpenChange.subscribe((isOpen:boolean) => {
120120
if (isOpen !== previousIsOpen) {
121121
// Only run transitions if the open state has changed.
122122
this._transitionController.stopAll();
@@ -139,27 +139,27 @@ export class SuiDropdownMenu extends SuiTransition implements AfterContentInit,
139139
});
140140
}
141141

142-
public set parentElement(value: ElementRef) {
142+
public set parentElement(value:ElementRef) {
143143
this._parentKeyDownListener = this._renderer
144-
.listen(value.nativeElement, "keydown", (e: KeyboardEvent) =>
144+
.listen(value.nativeElement, "keydown", (e:KeyboardEvent) =>
145145
this.onParentKeyDown(e));
146146
}
147147

148-
public set items(items: QueryList<SuiDropdownMenuItem>) {
148+
public set items(items:QueryList<SuiDropdownMenuItem>) {
149149
this._itemsQueryOverride = items;
150150
}
151151

152-
private get _itemsQuery(): QueryList<SuiDropdownMenuItem> {
152+
private get _itemsQuery():QueryList<SuiDropdownMenuItem> {
153153
return this._itemsQueryOverride || this._itemsQueryInternal;
154154
}
155155

156156
// Get the list of items, ignoring those that are disabled.
157-
private get _items(): SuiDropdownMenuItem[] {
157+
private get _items():SuiDropdownMenuItem[] {
158158
return this._itemsQuery.filter(i => !i.isDisabled);
159159
}
160160

161161
@HostListener("click", ["$event"])
162-
public onClick(e: HandledEvent & MouseEvent): void {
162+
public onClick(e:HandledEvent & MouseEvent):void {
163163
if (!e.eventHandled) {
164164
e.eventHandled = true;
165165

@@ -173,7 +173,7 @@ export class SuiDropdownMenu extends SuiTransition implements AfterContentInit,
173173
}
174174
}
175175

176-
public onParentKeyDown(e: KeyboardEvent): void {
176+
public onParentKeyDown(e:KeyboardEvent):void {
177177
// Only the root dropdown (i.e. not nested dropdowns) is responsible for keeping track of the currently selected item.
178178
if (this._service && this._service.isOpen && !this._service.isNested) {
179179
// Stop document events like scrolling while open.
@@ -186,7 +186,7 @@ export class SuiDropdownMenu extends SuiTransition implements AfterContentInit,
186186
// Gets the top selected item from the stack.
187187
const [selected] = this.selectedItems.slice(-1);
188188
// Keeping track of the menu containing the currently selected element allows us to easily determine its siblings.
189-
let selectedContainer: SuiDropdownMenu = this;
189+
let selectedContainer:SuiDropdownMenu = this;
190190
if (this.selectedItems.length >= 2) {
191191
const [selectedParent] = this.selectedItems.slice(-2);
192192
selectedContainer = selectedParent.childDropdownMenu;
@@ -240,7 +240,7 @@ export class SuiDropdownMenu extends SuiTransition implements AfterContentInit,
240240
}
241241
}
242242

243-
public resetSelection(): void {
243+
public resetSelection():void {
244244
this.selectedItems = [];
245245
this._items.forEach(i => {
246246
i.selectedClass = this.menuSelectedItemClass;
@@ -256,7 +256,7 @@ export class SuiDropdownMenu extends SuiTransition implements AfterContentInit,
256256
}
257257

258258
// Determines the item to next be selected, based on the keyboard input & the currently selected item.
259-
public updateSelection(selectedItem: SuiDropdownMenuItem, keyCode: KeyCode): SuiDropdownMenuItem {
259+
public updateSelection(selectedItem:SuiDropdownMenuItem, keyCode:KeyCode):SuiDropdownMenuItem {
260260
if (selectedItem) {
261261
// Remove the selected status on the previously selected item.
262262
selectedItem.isSelected = false;
@@ -265,7 +265,7 @@ export class SuiDropdownMenu extends SuiTransition implements AfterContentInit,
265265
let selectedIndex = this._items
266266
.findIndex(i => i === selectedItem);
267267

268-
let newSelection: SuiDropdownMenuItem;
268+
let newSelection:SuiDropdownMenuItem;
269269

270270
switch (keyCode) {
271271
case KeyCode.Enter:
@@ -298,9 +298,9 @@ export class SuiDropdownMenu extends SuiTransition implements AfterContentInit,
298298
return newSelection;
299299
}
300300

301-
public scrollToItem(item: SuiDropdownMenuItem): void {
302-
const menu: Element = this._element.nativeElement;
303-
const selectedRect: ClientRect = item.element.nativeElement.getBoundingClientRect();
301+
public scrollToItem(item:SuiDropdownMenuItem):void {
302+
const menu:Element = this._element.nativeElement;
303+
const selectedRect:ClientRect = item.element.nativeElement.getBoundingClientRect();
304304

305305
const menuRect = menu.getBoundingClientRect();
306306

@@ -317,16 +317,16 @@ export class SuiDropdownMenu extends SuiTransition implements AfterContentInit,
317317
menu.scrollTop += Math.round(scrollAmount);
318318
}
319319

320-
public ngAfterContentInit(): void {
320+
public ngAfterContentInit():void {
321321
this.onItemsChanged();
322322
this._itemsQuery.changes.subscribe(() => this.onItemsChanged());
323323
}
324324

325-
public ngOnDestroy(): void {
325+
public ngOnDestroy():void {
326326
this._parentKeyDownListener();
327327
}
328328

329-
private onItemsChanged(): void {
329+
private onItemsChanged():void {
330330
// We use `_items` rather than `items` in case one or more have become disabled.
331331
this.resetSelection();
332332
}

0 commit comments

Comments
 (0)