1- import { Component , ComponentInterface , Element , Event , EventEmitter , Host , Method , Prop , State , Watch , h } from '@stencil/core' ;
1+ import { Build , Component , ComponentInterface , Element , Event , EventEmitter , Host , Method , Prop , State , Watch , h } from '@stencil/core' ;
22
33import { getIonMode } from '../../global/ionic-global' ;
44import { Color , InputChangeEventDetail , StyleEventDetail , TextFieldTypes } from '../../interface' ;
@@ -66,7 +66,7 @@ export class Input implements ComponentInterface {
6666 /**
6767 * If `true`, the value will be cleared after focus upon edit. Defaults to `true` when `type` is `"password"`, `false` for all other types.
6868 */
69- @Prop ( { mutable : true } ) clearOnEdit ?: boolean ;
69+ @Prop ( ) clearOnEdit ?: boolean ;
7070
7171 /**
7272 * Set the amount of time, in milliseconds, to wait to trigger the `ionChange` event after each keystroke.
@@ -218,22 +218,22 @@ export class Input implements ComponentInterface {
218218 */
219219 @Event ( ) ionStyle ! : EventEmitter < StyleEventDetail > ;
220220
221- componentWillLoad ( ) {
222- // By default, password inputs clear after focus when they have content
223- if ( this . clearOnEdit === undefined && this . type === 'password' ) {
224- this . clearOnEdit = true ;
225- }
221+ connectedCallback ( ) {
226222 this . emitStyle ( ) ;
227- }
228-
229- componentDidLoad ( ) {
230223 this . debounceChanged ( ) ;
231-
232- this . ionInputDidLoad . emit ( ) ;
224+ if ( Build . isBrowser ) {
225+ this . el . dispatchEvent ( new CustomEvent ( 'ionInputDidLoad' , {
226+ detail : this . el
227+ } ) ) ;
228+ }
233229 }
234230
235- componentDidUnload ( ) {
236- this . ionInputDidUnload . emit ( ) ;
231+ disconnectedCallback ( ) {
232+ if ( Build . isBrowser ) {
233+ document . dispatchEvent ( new CustomEvent ( 'ionInputDidUnload' , {
234+ detail : this . el
235+ } ) ) ;
236+ }
237237 }
238238
239239 /**
@@ -255,6 +255,13 @@ export class Input implements ComponentInterface {
255255 return Promise . resolve ( this . nativeInput ! ) ;
256256 }
257257
258+ private shouldClearOnEdit ( ) {
259+ const { type, clearOnEdit } = this ;
260+ return ( clearOnEdit === undefined )
261+ ? type === 'password'
262+ : clearOnEdit ;
263+ }
264+
258265 private getValue ( ) : string {
259266 return this . value || '' ;
260267 }
@@ -295,7 +302,7 @@ export class Input implements ComponentInterface {
295302 }
296303
297304 private onKeydown = ( ) => {
298- if ( this . clearOnEdit ) {
305+ if ( this . shouldClearOnEdit ( ) ) {
299306 // Did the input value change after it was blurred and edited?
300307 if ( this . didBlurAfterEdit && this . hasValue ( ) ) {
301308 // Clear the input
@@ -327,7 +334,7 @@ export class Input implements ComponentInterface {
327334
328335 private focusChanged ( ) {
329336 // If clearOnEdit is enabled and the input blurred but has a value, set a flag
330- if ( this . clearOnEdit && ! this . hasFocus && this . hasValue ( ) ) {
337+ if ( ! this . hasFocus && this . shouldClearOnEdit ( ) && this . hasValue ( ) ) {
331338 this . didBlurAfterEdit = true ;
332339 }
333340 }
0 commit comments