diff --git a/demos/src/searchbar/pages/page-one/page-one.ts b/demos/src/searchbar/pages/page-one/page-one.ts index b59d9042bb..be9d678779 100644 --- a/demos/src/searchbar/pages/page-one/page-one.ts +++ b/demos/src/searchbar/pages/page-one/page-one.ts @@ -16,7 +16,7 @@ export class PageOne { filterItems(ev: any) { this.setItems(); - let val = ev.target.value; + let val = ev.value; if (val && val.trim() !== '') { this.items = this.items.filter(function(item) { diff --git a/src/components/searchbar/searchbar.ts b/src/components/searchbar/searchbar.ts index 04a7c4a13e..98c2935c54 100644 --- a/src/components/searchbar/searchbar.ts +++ b/src/components/searchbar/searchbar.ts @@ -47,7 +47,8 @@ import { Platform } from '../../platform/platform'; '[class.searchbar-has-value]': '_value', '[class.searchbar-active]': '_isActive', '[class.searchbar-show-cancel]': '_showCancelButton', - '[class.searchbar-left-aligned]': '_shouldAlignLeft' + '[class.searchbar-left-aligned]': '_shouldAlignLeft', + '[class.searchbar-has-focus]': '_isFocus' }, encapsulation: ViewEncapsulation.None }) @@ -150,10 +151,6 @@ export class Searchbar extends BaseInput { */ @Output() ionClear: EventEmitter = new EventEmitter(); - /** - * @hidden - */ - @HostBinding('class.searchbar-has-focus') _sbHasFocus: boolean; constructor( config: Config, @@ -213,7 +210,7 @@ export class Searchbar extends BaseInput { positionElements() { const isAnimated = this._animated; const prevAlignLeft = this._shouldAlignLeft; - const shouldAlignLeft = (!isAnimated || (this._value && this._value.toString().trim() !== '') || this._sbHasFocus === true); + const shouldAlignLeft = (!isAnimated || (this._value && this._value.toString().trim() !== '') || this._isFocus === true); this._shouldAlignLeft = shouldAlignLeft; if (this._mode !== 'ios') { @@ -268,7 +265,7 @@ export class Searchbar extends BaseInput { if (!this._cancelButton || !this._cancelButton.nativeElement) { return; } - const showShowCancel = this._sbHasFocus; + const showShowCancel = this._isFocus; if (showShowCancel !== this._isCancelVisible) { var cancelStyleEle = this._cancelButton.nativeElement; var cancelStyle = cancelStyleEle.style; @@ -298,8 +295,9 @@ export class Searchbar extends BaseInput { * Sets the Searchbar to focused and active on input focus. */ inputFocused(ev: UIEvent) { - this._fireFocus(); this._isActive = true; + this._fireFocus(); + this.positionElements(); } /** @@ -316,6 +314,7 @@ export class Searchbar extends BaseInput { return; } this._fireBlur(); + this.positionElements(); } /** diff --git a/src/components/searchbar/test/basic/pages/root-page/root-page.ts b/src/components/searchbar/test/basic/pages/root-page/root-page.ts index 3027cf40e0..2e4dfa5f7d 100644 --- a/src/components/searchbar/test/basic/pages/root-page/root-page.ts +++ b/src/components/searchbar/test/basic/pages/root-page/root-page.ts @@ -19,23 +19,23 @@ export class RootPage { } onClearSearchbar(ev: any) { - console.log('ionClear', ev.target.value); + console.log('ionClear', ev.value); } onCancelSearchbar(ev: any) { - console.log('ionCancel', ev.target.value); + console.log('ionCancel', ev.value); } triggerInput(ev: any) { - console.log('ionInput', ev.target.value); + console.log('ionInput', ev.value); } inputBlurred(ev: any) { - console.log('ionBlur', ev.target.value); + console.log('ionBlur', ev.value); } inputFocused(ev: any) { - console.log('ionFocus', ev.target.value); + console.log('ionFocus', ev.value); } ngAfterViewInit() { diff --git a/src/components/searchbar/test/nav/pages/search-page/search-page.ts b/src/components/searchbar/test/nav/pages/search-page/search-page.ts index 316029c459..4724ece332 100644 --- a/src/components/searchbar/test/nav/pages/search-page/search-page.ts +++ b/src/components/searchbar/test/nav/pages/search-page/search-page.ts @@ -63,7 +63,7 @@ export class SearchPage { this.initializeItems(); // set q to the value of the searchbar - var q = ev.target.value; + var q = ev.value; // if the value is an empty string don't filter the items if (!q || q.trim() === '') {