autocomplete fix

This commit is contained in:
Diamantis Tziotzios 2019-02-15 10:51:21 +02:00
parent da2c6f7ee5
commit 54779bf53f
3 changed files with 15 additions and 8 deletions

View File

@ -1,15 +1,13 @@
<div class="row auto-complete">
<mat-chip-list #chipList [disabled]="disabled">
<mat-chip-list #chipList [disabled]="disabled" class="chip-list">
<mat-chip *ngIf="value" [removable]="true" (removed)="chipRemove()">
{{_displayFn(value)}}
<mat-icon matChipRemove *ngIf="!disabled">cancel</mat-icon>
</mat-chip>
<input matInput class="col" autocomplete="off" [placeholder]="placeholder" [matAutocomplete]="auto" [ngModel]="_inputValue" (ngModelChange)="_inputValueChange($event)" [disabled]="disabled || (value !== null)" (focus)="_onInputFocus()" [matChipInputFor]="chipList" [matChipInputSeparatorKeyCodes]="separatorKeysCodes" [matChipInputAddOnBlur]="true">
<input matInput class="col" autocomplete="off" [placeholder]="placeholder" [matAutocomplete]="auto" [ngModel]="_inputValue" (ngModelChange)="_inputValueChange($event)" [disabled]="disabled || (value != null && value !== '')" (focus)="_onInputFocus()" [matChipInputFor]="chipList" [matChipInputSeparatorKeyCodes]="separatorKeysCodes" [matChipInputAddOnBlur]="true">
</mat-chip-list>
<mat-progress-spinner mode="indeterminate" [class.not-loading]="!loading" [diameter]="17"></mat-progress-spinner>
<mat-progress-spinner class="progress-loader" mode="indeterminate" [class.not-loading]="!loading" [diameter]="17"></mat-progress-spinner>
<mat-autocomplete #auto="matAutocomplete" [displayWith]="_displayFn.bind(this)" (optionSelected)="_optionSelected($event)">
<span *ngIf="_groupedItems">
<mat-optgroup *ngFor="let group of _groupedItems | async" [label]="group.title">

View File

@ -5,9 +5,18 @@
.not-loading {
display: none;
}
.chip-list {
width: 100%;
}
.progress-loader {
position: absolute;
right: 0;
}
}
.two-line-mat-option {
height: 3.5em;
line-height: 1.2em;
}
}

View File

@ -75,7 +75,7 @@ export class SingleAutoCompleteComponent implements OnInit, MatFormFieldControl<
}
set value(value: any | null) {
this._selectedValue = value;
this._inputValue = " ";
if (value && value != "") { this._inputValue = " "; }
this.stateChanges.next();
}
private _selectedValue;
@ -149,7 +149,7 @@ export class SingleAutoCompleteComponent implements OnInit, MatFormFieldControl<
_optionSelected(event: MatAutocompleteSelectedEvent) {
this._setValue(this.configuration.valueAssign ? this.configuration.valueAssign(event.option.value) : event.option.value);
this._inputValue = " ";;
//this._inputValue = " ";
this.stateChanges.next();
this.optionSelected.emit(event.option.value);
}