Skip to content

Commit

Permalink
fix(searchbar): fix crash on cancel event (#16181)
Browse files Browse the repository at this point in the history
fixes #16143
  • Loading branch information
manucorporat authored Nov 1, 2018
1 parent fce30eb commit 9c79d98
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions core/src/components/searchbar/searchbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { createColorClasses } from '../../utils/theme';
})
export class Searchbar implements ComponentInterface {

private nativeInput!: HTMLInputElement;
private nativeInput?: HTMLInputElement;
private isCancelVisible = false;
private shouldAlignLeft = true;

Expand Down Expand Up @@ -164,7 +164,9 @@ export class Searchbar implements ComponentInterface {
*/
@Method()
setFocus() {
this.nativeInput.focus();
if (this.nativeInput) {
this.nativeInput.focus();
}
}

/**
Expand Down Expand Up @@ -202,7 +204,9 @@ export class Searchbar implements ComponentInterface {
this.ionCancel.emit();
this.onClearInput();

this.nativeInput.blur();
if (this.nativeInput) {
this.nativeInput.blur();
}
}

/**
Expand Down Expand Up @@ -262,8 +266,11 @@ export class Searchbar implements ComponentInterface {
* Positions the input placeholder
*/
private positionPlaceholder() {
const isRTL = this.doc.dir === 'rtl';
const inputEl = this.nativeInput;
if (!inputEl) {
return;
}
const isRTL = this.doc.dir === 'rtl';
const iconEl = (this.el.shadowRoot || this.el).querySelector('.searchbar-search-icon') as HTMLElement;

if (this.shouldAlignLeft) {
Expand Down

0 comments on commit 9c79d98

Please sign in to comment.