diff --git a/ionic/components/searchbar/searchbar.ts b/ionic/components/searchbar/searchbar.ts index f4d44cdec0..1e28f22852 100644 --- a/ionic/components/searchbar/searchbar.ts +++ b/ionic/components/searchbar/searchbar.ts @@ -40,17 +40,18 @@ import {Button} from '../button/button'; }, template: '
' + - '', + '', directives: [FORM_DIRECTIVES, NgIf, NgClass, Icon, Button, forwardRef(() => SearchbarInput)] }) export class Searchbar extends Ion { @ViewChild(forwardRef(() => SearchbarInput)) searchbarInput; query: string; + blurInput = true; constructor( elementRef: ElementRef, @@ -110,7 +111,13 @@ export class Searchbar extends Ion { * based on whether there is a value in the searchbar or not. */ inputBlurred() { - console.log("Input Blurred"); + // blurInput determines if it should blur + // if we are clearing the input we still want to stay focused in the input + if (this.blurInput == false) { + this.searchbarInput.elementRef.nativeElement.focus(); + this.blurInput = true; + return; + } this.isFocused = false; this.shouldLeftAlign = this.searchbarInput.value && this.searchbarInput.value.trim() != ''; } @@ -122,19 +129,18 @@ export class Searchbar extends Ion { clearInput() { this.searchbarInput.writeValue(''); this.searchbarInput.onChange(''); + this.blurInput = false; } /** * @private - * Blurs the input field, clears the input field and removes the left align + * Clears the input field and tells the input to blur since + * the clearInput function doesn't want the input to blur * then calls the custom cancel function if the user passed one in. */ cancelSearchbar(event, value) { - console.log("Clicked Cancel"); - this.searchbarInput.elementRef.nativeElement.blur(); this.clearInput(); - this.isFocused = false; - this.shouldLeftAlign = false; + this.blurInput = true; this.cancelButtonAction && this.cancelButtonAction(event, value); }