Skip to content

Commit 7e63650

Browse files
committed
fix(searchbar): autocomplete, autocorrect and type works again
fixes #7744
1 parent d03182e commit 7e63650

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

src/components/searchbar/searchbar.ts

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ import { Debouncer } from '../../util/debouncer';
3434
'<ion-icon name="arrow-back"></ion-icon>' +
3535
'</button>' +
3636
'<div #searchbarIcon class="searchbar-search-icon"></div>' +
37-
'<input #searchbarInput [(ngModel)]="_value" [attr.placeholder]="placeholder" (input)="inputChanged($event)" (blur)="inputBlurred($event)" (focus)="inputFocused($event)" class="searchbar-input">' +
37+
'<input #searchbarInput [(ngModel)]="_value" ' +
38+
'[attr.placeholder]="placeholder" ' +
39+
'[attr.type]="type" ' +
40+
'[attr.autocomplete]="_autocomplete" ' +
41+
'[attr.autocorrect]="_autocorrect" ' +
42+
'[attr.spellcheck]="_spellcheck" ' +
43+
'(input)="inputChanged($event)" (blur)="inputBlurred($event)" (focus)="inputFocused($event)" class="searchbar-input">' +
3844
'<button ion-button clear class="searchbar-clear-icon" (click)="clearInput($event)" (mousedown)="clearInput($event)" type="button"></button>' +
3945
'</div>' +
4046
'<button ion-button #cancelButton [tabindex]="_isActive ? 1 : -1" clear (click)="cancelSearchbar($event)" (mousedown)="cancelSearchbar($event)" class="searchbar-ios-cancel" type="button">{{cancelButtonText}}</button>',
@@ -52,8 +58,10 @@ export class Searchbar extends Ion {
5258
_shouldBlur: boolean = true;
5359
_shouldAlignLeft: boolean = true;
5460
_isCancelVisible: boolean = false;
61+
_spellcheck: boolean = false;
62+
_autocomplete: string = 'off';
63+
_autocorrect: string = 'off';
5564
_isActive: boolean = false;
56-
_searchbarInput: ElementRef;
5765
_debouncer: Debouncer = new Debouncer(250);
5866

5967
/**
@@ -101,17 +109,26 @@ export class Searchbar extends Ion {
101109
/**
102110
* @input {string} Set the input's autocomplete property. Values: `"on"`, `"off"`. Default `"off"`.
103111
*/
104-
@Input() autocomplete: string;
112+
@Input()
113+
set autocomplete(val: string) {
114+
this._autocomplete = (val === '' || val === 'on') ? 'on' : this._config.get('autocomplete', 'off');
115+
}
105116

106117
/**
107118
* @input {string} Set the input's autocorrect property. Values: `"on"`, `"off"`. Default `"off"`.
108119
*/
109-
@Input() autocorrect: string;
120+
@Input()
121+
set autocorrect(val: string) {
122+
this._autocorrect = (val === '' || val === 'on') ? 'on' : this._config.get('autocorrect', 'off');
123+
}
110124

111125
/**
112126
* @input {string|boolean} Set the input's spellcheck property. Values: `true`, `false`. Default `false`.
113127
*/
114-
@Input() spellcheck: string|boolean;
128+
@Input()
129+
set spellcheck(val: string | boolean) {
130+
this._spellcheck = (val === '' || val === 'true' || val === true) ? true : this._config.getBoolean('spellcheck', false);
131+
}
115132

116133
/**
117134
* @input {string} Set the type of the input. Values: `"text"`, `"password"`, `"email"`, `"number"`, `"search"`, `"tel"`, `"url"`. Default `"search"`.
@@ -169,30 +186,7 @@ export class Searchbar extends Ion {
169186
}
170187
}
171188

172-
/**
173-
* @private
174-
*/
175-
@ViewChild('searchbarInput')
176-
set searchbarInput(searchbarInput: ElementRef) {
177-
this._searchbarInput = searchbarInput;
178-
179-
let inputEle = searchbarInput.nativeElement;
180-
181-
// By defalt set autocomplete="off" unless specified by the input
182-
let autoComplete = (this.autocomplete === '' || this.autocomplete === 'on') ? 'on' : this._config.get('autocomplete', 'off');
183-
inputEle.setAttribute('autocomplete', autoComplete);
184-
185-
// by default set autocorrect="off" unless specified by the input
186-
let autoCorrect = (this.autocorrect === '' || this.autocorrect === 'on') ? 'on' : this._config.get('autocorrect', 'off');
187-
inputEle.setAttribute('autocorrect', autoCorrect);
188-
189-
// by default set spellcheck="false" unless specified by the input
190-
let spellCheck = (this.spellcheck === '' || this.spellcheck === 'true' || this.spellcheck === true) ? true : this._config.getBoolean('spellcheck', false);
191-
inputEle.setAttribute('spellcheck', spellCheck);
192-
193-
// by default set type="search" unless specified by the input
194-
inputEle.setAttribute('type', this.type);
195-
}
189+
@ViewChild('searchbarInput') _searchbarInput: ElementRef;
196190

197191
@ViewChild('searchbarIcon') _searchbarIcon: ElementRef;
198192

src/components/searchbar/test/basic/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<ion-content>
22
<h5 padding-left> Search - Default </h5>
3-
<ion-searchbar [(ngModel)]="defaultSearch" showCancelButton debounce="500" (ionInput)="triggerInput($event)" (ionBlur)="inputBlurred($event)" (ionFocus)="inputFocused($event)" (ionCancel)="onCancelSearchbar($event)" (ionClear)="onClearSearchbar($event)"></ion-searchbar>
3+
<ion-searchbar [(ngModel)]="defaultSearch" type="tel" showCancelButton debounce="500" (ionInput)="triggerInput($event)" (ionBlur)="inputBlurred($event)" (ionFocus)="inputFocused($event)" (ionCancel)="onCancelSearchbar($event)" (ionClear)="onClearSearchbar($event)"></ion-searchbar>
44

55
<h5 padding-left> Search - Animated </h5>
66
<ion-searchbar animated="true" showCancelButton debounce="500" (ionInput)="triggerInput($event)" (ionBlur)="inputBlurred($event)" (ionFocus)="inputFocused($event)" (ionCancel)="onCancelSearchbar($event)" (ionClear)="onClearSearchbar($event)"></ion-searchbar>

0 commit comments

Comments
 (0)