Skip to content

Commit

Permalink
Fixed #4578 and #4579
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici authored and Çağatay Çivici committed Jan 23, 2018
1 parent 3489d81 commit 1d0b23e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/app/components/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export const DROPDOWN_VALUE_ACCESSOR: any = {
transition('hidden => visible', animate('400ms ease-out'))
])
],
host: {
'[class.ui-inputwrapper-filled]': 'filled',
'[class.ui-inputwrapper-focus]': 'focus'
},
providers: [DomHandler,ObjectUtils,DROPDOWN_VALUE_ACCESSOR]
})
export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterViewChecked,OnDestroy,ControlValueAccessor {
Expand Down Expand Up @@ -126,6 +130,8 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView

@Input() optionLabel: string;

@Input() autoSelectFirst: boolean = true;

@Input() emptyFilterMessage: string = 'No results found';

@Output() onChange: EventEmitter<any> = new EventEmitter();
Expand Down Expand Up @@ -167,6 +173,8 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
hover: boolean;

focus: boolean;

filled: boolean;

public panelVisible: boolean = false;

Expand Down Expand Up @@ -270,7 +278,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
this.itemClick = true;
this.selectItem(event, option);
this.focusViewChild.nativeElement.focus();

this.filled = true;
this.hide();
}

Expand Down Expand Up @@ -323,6 +331,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
this.value = value;
this.updateSelectedOption(value);
this.updateEditableLabel();
this.updateFilledState();
this.cd.markForCheck();
}

Expand All @@ -336,7 +345,7 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView

updateSelectedOption(val: any): void {
this.selectedOption = this.findOption(val, this.optionsToDisplay);
if(!this.placeholder && !this.selectedOption && this.optionsToDisplay && this.optionsToDisplay.length && !this.editable) {
if(this.autoSelectFirst && !this.placeholder && !this.selectedOption && this.optionsToDisplay && this.optionsToDisplay.length && !this.editable) {
this.selectedOption = this.optionsToDisplay[0];
}
this.selectedOptionUpdated = true;
Expand Down Expand Up @@ -590,6 +599,10 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
this.documentClickListener = null;
}
}

updateFilledState() {
this.filled = (this.value != null);
}

ngOnDestroy() {
this.initialized = false;
Expand Down
12 changes: 12 additions & 0 deletions src/app/components/multiselect/multiselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export const MULTISELECT_VALUE_ACCESSOR: any = {
</div>
</div>
`,
host: {
'[class.ui-inputwrapper-filled]': 'filled',
'[class.ui-inputwrapper-focus]': 'focus'
},
providers: [DomHandler,ObjectUtils,MULTISELECT_VALUE_ACCESSOR]
})
export class MultiSelect implements OnInit,AfterViewInit,AfterContentInit,AfterViewChecked,OnDestroy,ControlValueAccessor {
Expand Down Expand Up @@ -139,6 +143,8 @@ export class MultiSelect implements OnInit,AfterViewInit,AfterContentInit,AfterV
public valuesAsString: string;

public focus: boolean;

filled: boolean;

public documentClickListener: any;

Expand Down Expand Up @@ -222,8 +228,13 @@ export class MultiSelect implements OnInit,AfterViewInit,AfterContentInit,AfterV
writeValue(value: any) : void {
this.value = value;
this.updateLabel();
this.updateFilledState();
this.cd.markForCheck();
}

updateFilledState() {
this.filled = (this.valuesAsString != null && this.valuesAsString.length > 0);
}

registerOnChange(fn: Function): void {
this.onModelChange = fn;
Expand All @@ -247,6 +258,7 @@ export class MultiSelect implements OnInit,AfterViewInit,AfterContentInit,AfterV
this.onModelChange(this.value);
this.onChange.emit({originalEvent: event, value: this.value, itemValue: value});
this.updateLabel();
this.updateFilledState();
}

isSelected(value) {
Expand Down

0 comments on commit 1d0b23e

Please sign in to comment.