Skip to content

Commit

Permalink
refactor(select): Cleaned up focusout code
Browse files Browse the repository at this point in the history
  • Loading branch information
edcarroll committed Jul 4, 2017
1 parent a578e7d commit dab9323
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 45 deletions.
12 changes: 1 addition & 11 deletions demo/src/app/pages/development/test/test.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
<demo-page-content>
<h2 class="ui dividing header">Examples</h2>
<div class="ui segment">
<div class="ui fluid left icon input">
<i class="calendar icon"></i>
<input suiDatepicker
[(ngModel)]="date"
pickerMode="month"
[pickerMaxDate]="maxDate"
[pickerMinDate]="minDate"
[pickerFirstDayOfWeek]="3">
</div>
<br>
<p>{{ date }}</p>

</div>
</demo-page-content>
20 changes: 2 additions & 18 deletions demo/src/app/pages/development/test/test.page.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
import { Component, AfterViewInit, ViewChild, TemplateRef } from "@angular/core";
import { FormControl, Validators } from "@angular/forms";

@Component({
selector: "demo-page-test",
templateUrl: "./test.page.html"
})
export class TestPage {
public date:Date = new Date();

public minDate:Date;
public maxDate:Date;

constructor() {
const today = new Date();

this.minDate = new Date(today.getFullYear(), today.getMonth() - 2);
this.maxDate = new Date(today.getFullYear(), today.getMonth() + 2);

console.log(this.minDate);
console.log(this.maxDate);
}

public log(item:any):void {
console.log(item);
}
constructor() {}
}
8 changes: 3 additions & 5 deletions src/modules/dropdown/directives/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,9 @@ export class SuiDropdown implements AfterContentInit {

@HostListener("focusout", ["$event"])
private onFocusOut(e:FocusEvent):void {
setTimeout(() => {
if (!this._element.nativeElement.contains(document.activeElement)) {
this.externallyClose();
}
});
if (!this._element.nativeElement.contains(e.relatedTarget)) {
this.externallyClose();
}
}

@HostListener("keypress", ["$event"])
Expand Down
8 changes: 3 additions & 5 deletions src/modules/search/components/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,9 @@ export class SuiSearch<T> implements AfterViewInit {

@HostListener("focusout", ["$event"])
private onFocusOut(e:FocusEvent):void {
setTimeout(() => {
if (!this._element.nativeElement.contains(document.activeElement)) {
this.dropdownService.setOpenState(false);
}
});
if (!this._element.nativeElement.contains(e.relatedTarget)) {
this.dropdownService.setOpenState(false);
}
}

@HostListener("document:click", ["$event"])
Expand Down
10 changes: 4 additions & 6 deletions src/modules/select/classes/select-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,10 @@ export abstract class SuiSelectBase<T, U> implements AfterContentInit {

@HostListener("focusout", ["$event"])
private onFocusOut(e:FocusEvent):void {
setTimeout(() => {
if (!this._element.nativeElement.contains(document.activeElement)) {
this.dropdownService.setOpenState(false);
this.onTouched.emit();
}
});
if (!this._element.nativeElement.contains(e.relatedTarget)) {
this.dropdownService.setOpenState(false);
this.onTouched.emit();
}
}

@HostListener("keypress", ["$event"])
Expand Down

0 comments on commit dab9323

Please sign in to comment.