Skip to content

Commit

Permalink
feat(autocomplete): input for focus on value change (#2356)
Browse files Browse the repository at this point in the history
  • Loading branch information
jornetsimon authored Jun 3, 2020
1 parent c12873d commit ab15806
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
} from '../cdk/a11y/descendant-key-manager';
import { NbAutocompleteComponent } from './autocomplete.component';
import { NbOptionComponent } from '../option/option.component';
import { convertToBoolProperty } from '../helpers';

/**
* The `NbAutocompleteDirective` provides a capability to expand input with
Expand Down Expand Up @@ -135,6 +136,18 @@ export class NbAutocompleteDirective<T> implements OnDestroy, AfterViewInit, Con
this._autocomplete = autocomplete;
}

/**
* Determines if the input will be focused when the control value is changed
* */
@Input()
get focusInputOnValueChange(): boolean {
return this._focusInputOnValueChange;
}
set focusInputOnValueChange(value: boolean) {
this._focusInputOnValueChange = convertToBoolProperty(value);
}
protected _focusInputOnValueChange: boolean = true;

@HostBinding('class.nb-autocomplete-position-top')
get top(): boolean {
return this.isOpen && this.autocomplete.options.length && this.autocomplete.overlayPosition === NbPosition.TOP;
Expand Down Expand Up @@ -301,7 +314,9 @@ export class NbAutocompleteDirective<T> implements OnDestroy, AfterViewInit, Con
}
this.setHostInputValue(value);
this._onChange(value);
this.hostRef.nativeElement.focus();
if (this.focusInputOnValueChange) {
this.hostRef.nativeElement.focus();
}
this.autocomplete.emitSelected(value);
this.hide();
}
Expand Down

0 comments on commit ab15806

Please sign in to comment.