Skip to content

Commit

Permalink
Merge pull request #8 from Zefling/master
Browse files Browse the repository at this point in the history
Fix various click problems
  • Loading branch information
plantain-00 authored Aug 8, 2017
2 parents 48c96dc + 34e70fe commit b292e45
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/angular.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,20 @@ export class Select2 implements ControlValueAccessor {
this.toggleOpenAndClose();
}
if (!this.ifParentContainsId(e.target as HTMLElement, this._id)) {
this.focused = false;
window.document.body.removeEventListener("click", this._clickDetectionFc);
this._clickDetection = false;
this.clickExit();
}
} else if (this.isOpen && !this.ifParentContainsId(e.target as HTMLElement, this._id)) {
this.toggleOpenAndClose();
this.clickExit();
}
}

clickExit() {
this.focused = false;
window.document.body.removeEventListener("click", this._clickDetectionFc);
this._clickDetection = false;
}

ifParentContainsClass(element: HTMLElement, cssClass: string): boolean {
return this.getParentElementByClass(element, cssClass) !== null;
}
Expand Down Expand Up @@ -463,6 +470,10 @@ export class Select2 implements ControlValueAccessor {
}
}

trackBy(index: number, item: common.Select2Option): any {
return item.value;
}

searchUpdate(e: Event) {
this.searchText = (e.target as HTMLInputElement).value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/angular.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
role="tree"
tabindex="-1"
(keydown)="keyDown($event)">
<ng-template ngFor [ngForOf]="filteredData" let-groupOrOption>
<ng-template ngFor [ngForOf]="filteredData" let-groupOrOption [ngForTrackBy]="trackBy">
<li *ngIf="groupOrOption.options"
class="select2-results__option"
role="group">
<strong [attr.class]="'select2-results__group' + (groupOrOption.classes ? ' ' + groupOrOption.classes : '')">{{groupOrOption.label}}</strong>
<ul class="select2-results__options select2-results__options--nested">
<li *ngFor="let option of groupOrOption.options"
<li *ngFor="let option of groupOrOption.options; trackBy:trackBy"
[class]="getOptionStyle(option)"
role="treeitem"
[attr.aria-selected]="isSelected(option)"
Expand Down

0 comments on commit b292e45

Please sign in to comment.