Skip to content

Commit

Permalink
* removeFocus setFocus methods produce unhandled errors kolkov#45
Browse files Browse the repository at this point in the history
fixed
* onEnter method produce unhandled errors kolkov#19 fixed
  • Loading branch information
RomanKyklin committed Nov 25, 2021
1 parent d3ad811 commit 71edf33
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion projects/ngx-dadata/src/lib/ngx-dadata.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class NgxDadataComponent implements OnInit, ControlValueAccessor, OnChang
// @Output() selectedData = new EventEmitter<DaDataAddress | DaDataFIO | DaDataBank | DaDataParty | DaDataEmail>();
// @Output() selectedString = new EventEmitter<string>();

@ViewChild('inputValue', { static: true }) inputValue: ElementRef;
@ViewChild('inputValue', {static: true}) inputValue: ElementRef;

private inputString$ = new Subject<string>();

Expand Down Expand Up @@ -182,6 +182,9 @@ export class NgxDadataComponent implements OnInit, ControlValueAccessor, OnChang

onEnter(event: KeyboardEvent) {
this.selectedSuggestion = this.data[this.currentFocus];
if (!this.selectedSuggestion) {
return;
}
this.inputValue.nativeElement.value = this.selectedSuggestion.value;
this.data = [];
this.currentFocus = -1;
Expand All @@ -193,12 +196,18 @@ export class NgxDadataComponent implements OnInit, ControlValueAccessor, OnChang

setFocus(id: number) {
const activeEl = document.getElementById(id + 'item');
if (!activeEl) {
return;
}
this.r.addClass(activeEl, 'active');
}

removeFocus(id: number) {
if (id !== -1) {
const activeEl = document.getElementById(id + 'item');
if (!activeEl) {
return;
}
this.r.removeClass(activeEl, 'active');
}
}
Expand Down

0 comments on commit 71edf33

Please sign in to comment.