Skip to content

Commit

Permalink
Fixed #4013
Browse files Browse the repository at this point in the history
  • Loading branch information
Merve7 committed Sep 22, 2017
1 parent 94d0333 commit 0c8fee4
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/app/components/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const DROPDOWN_VALUE_ACCESSOR: any = {
<input #in [attr.id]="inputId" type="text" [attr.aria-label]="selectedOption ? selectedOption.label : ' '" readonly (focus)="onInputFocus($event)" role="listbox"
(blur)="onInputBlur($event)" (keydown)="onKeydown($event)" [disabled]="disabled" [attr.tabindex]="tabindex" [attr.autofocus]="autofocus">
</div>
<label [ngClass]="{'ui-dropdown-label ui-inputtext ui-corner-all':true,'ui-dropdown-label-empty':(label === null)}" *ngIf="!editable&&(label !== null)">{{label||'empty'}}</label>
<label [ngClass]="{'ui-dropdown-label ui-inputtext ui-corner-all ui-placeholder':true}" *ngIf="!editable&&(label === null)">{{placeholder}}</label>
<label [ngClass]="{'ui-dropdown-label ui-inputtext ui-corner-all':true,'ui-dropdown-label-empty':(label === null ||label.length === 0)}" *ngIf="!editable&&selectedOption">{{label||'empty'}}</label>
<label [ngClass]="{'ui-dropdown-label ui-inputtext ui-corner-all ui-placeholder':true}" *ngIf="!editable&&!selectedOption">{{placeholder}}</label>
<input #editableInput type="text" [attr.aria-label]="selectedOption ? selectedOption.label : ' '" class="ui-dropdown-label ui-inputtext ui-corner-all" *ngIf="editable" [disabled]="disabled" [attr.placeholder]="placeholder"
(click)="onEditableInputClick($event)" (input)="onEditableInputChange($event)" (focus)="onEditableInputFocus($event)" (blur)="onInputBlur($event)">
<div class="ui-dropdown-trigger ui-state-default ui-corner-right">
Expand All @@ -45,8 +45,8 @@ export const DROPDOWN_VALUE_ACCESSOR: any = {
</div>
<div #itemswrapper class="ui-dropdown-items-wrapper" [style.max-height]="scrollHeight||'auto'">
<ul class="ui-dropdown-items ui-dropdown-list ui-widget-content ui-widget ui-corner-all ui-helper-reset" *ngIf="lazy ? panelVisible : true">
<li *ngFor="let option of optionsToDisplay;let i=index"
[ngClass]="{'ui-dropdown-item ui-corner-all':true, 'ui-state-highlight':(selectedOption == option),
<li *ngFor="let option of optionsToDisplay;let i=index"
[ngClass]="{'ui-dropdown-item ui-corner-all':true, 'ui-state-highlight':(selectedOption == option),
'ui-dropdown-item-empty':!option.label||option.label.length === 0}"
(click)="onItemClick($event, option)">
<span *ngIf="!itemTemplate">{{option.label||'empty'}}</span>
Expand Down Expand Up @@ -118,7 +118,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
@Output() onFocus: EventEmitter<any> = new EventEmitter();

@Output() onBlur: EventEmitter<any> = new EventEmitter();

@ViewChild('container') containerViewChild: ElementRef;

@ViewChild('panel') panelViewChild: ElementRef;
Expand All @@ -134,7 +134,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
@ContentChildren(PrimeTemplate) templates: QueryList<any>;

public itemTemplate: TemplateRef<any>;

selectedOption: SelectItem;

_options: SelectItem[];
Expand All @@ -158,7 +158,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
public documentClickListener: any;

public optionsChanged: boolean;

public panel: HTMLDivElement;

public container: HTMLDivElement;
Expand All @@ -172,12 +172,12 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
public itemClick: boolean;

public hoveredItem: any;

public selectedOptionUpdated: boolean;

public filterValue: string;
constructor(public el: ElementRef, public domHandler: DomHandler, public renderer: Renderer2, private cd: ChangeDetectorRef,

constructor(public el: ElementRef, public domHandler: DomHandler, public renderer: Renderer2, private cd: ChangeDetectorRef,
public objectUtils: ObjectUtils, public zone: NgZone) {}

ngAfterContentInit() {
Expand All @@ -193,7 +193,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
}
});
}

ngOnInit() {
this.optionsToDisplay = this.options;
this.updateSelectedOption(null);
Expand All @@ -214,10 +214,10 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
}
}

ngAfterViewInit() {
ngAfterViewInit() {
this.container = <HTMLDivElement> this.containerViewChild.nativeElement;
this.panel = <HTMLDivElement> this.panelViewChild.nativeElement;
this.itemsWrapper = <HTMLDivElement> this.itemsWrapperViewChild.nativeElement;
this.panel = <HTMLDivElement> this.panelViewChild.nativeElement;
this.itemsWrapper = <HTMLDivElement> this.itemsWrapperViewChild.nativeElement;

if(this.editable) {
this.updateEditableLabel();
Expand All @@ -237,33 +237,33 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
get label(): string {
return (this.selectedOption ? this.selectedOption.label : null);
}

updateEditableLabel(): void {
if(this.editableInputViewChild && this.editableInputViewChild.nativeElement) {
this.editableInputViewChild.nativeElement.value = (this.selectedOption ? this.selectedOption.label : this.value||'');
}
}

onItemClick(event, option) {
this.itemClick = true;
this.selectItem(event, option);
this.focusViewChild.nativeElement.focus();

this.hide();
}

selectItem(event, option) {
if(this.selectedOption != option) {
this.selectedOption = option;
this.value = option.value;

this.onModelChange(this.value);
this.updateEditableLabel();
this.onChange.emit({
originalEvent: event,
value: this.value
});
}
}

}

Expand All @@ -280,7 +280,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
setTimeout(() => {
this.updateDimensions();
this.alignPanel();
}, 1);
}, 1);
});
}

Expand Down Expand Up @@ -331,7 +331,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
setDisabledState(val: boolean): void {
this.disabled = val;
}

updateDimensions() {
if(this.autoWidth) {
let select = this.domHandler.findSingle(this.el.nativeElement, 'select');
Expand All @@ -340,7 +340,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
}
}
}

onMouseclick(event) {
if(this.disabled||this.readonly) {
return;
Expand Down Expand Up @@ -377,14 +377,14 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView

onEditableInputChange(event) {
this.value = event.target.value;
this.updateSelectedOption(this.value);
this.updateSelectedOption(this.value);
this.onModelChange(this.value);
this.onChange.emit({
originalEvent: event,
value: this.value
});
}

onShow() {
if(this.options && this.options.length) {
this.alignPanel();
Expand Down Expand Up @@ -452,7 +452,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
}
else if(this.optionsToDisplay) {
this.selectItem(event, this.optionsToDisplay[0]);
}
}
}

event.preventDefault();
Expand All @@ -462,7 +462,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
//up
case 38:
if(selectedItemIndex > 0) {
let prevItemIndex = selectedItemIndex - 1;
let prevItemIndex = selectedItemIndex - 1;
this.selectItem(event, this.optionsToDisplay[prevItemIndex]);
this.selectedOptionUpdated = true;
}
Expand All @@ -480,7 +480,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
break;

//enter
case 13:
case 13:
this.hide();

event.preventDefault();
Expand All @@ -493,8 +493,8 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
break;
}
}
findOptionIndex(val: any, opts: SelectItem[]): number {

findOptionIndex(val: any, opts: SelectItem[]): number {
let index: number = -1;
if(opts) {
for(let i = 0; i < opts.length; i++) {
Expand All @@ -504,7 +504,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
}
}
}

return index;
}

Expand Down Expand Up @@ -554,7 +554,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
this.itemClick = false;
this.cd.markForCheck();
});
}
}
}

unbindDocumentClickListener() {
Expand All @@ -563,7 +563,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
this.documentClickListener = null;
}
}

ngOnDestroy() {
this.initialized = false;

Expand Down

0 comments on commit 0c8fee4

Please sign in to comment.