@@ -38,12 +38,12 @@ export default {
3838 data ( ) {
3939 const { value, defaultValue } = this . $props ;
4040 return {
41- stateValue : fixControlledValue ( ! hasProp ( this , 'value' ) ? defaultValue : value ) ,
41+ stateValue : ! hasProp ( this , 'value' ) ? defaultValue : value ,
4242 } ;
4343 } ,
4444 watch : {
4545 value ( val ) {
46- this . stateValue = fixControlledValue ( val ) ;
46+ this . stateValue = val ;
4747 } ,
4848 } ,
4949 mounted ( ) {
@@ -95,6 +95,21 @@ export default {
9595 if ( ! e . target . composing ) {
9696 this . $emit ( 'change.value' , value ) ;
9797 }
98+ let event = e ;
99+ if ( e . type === 'click' && this . $refs . input ) {
100+ // click clear icon
101+ event = { ...e } ;
102+ event . target = this . $refs . input ;
103+ event . currentTarget = this . $refs . input ;
104+ const originalInputValue = this . $refs . input . value ;
105+ // change input value cause e.target.value should be '' when clear input
106+ this . $refs . input . value = '' ;
107+ this . $emit ( 'change' , event ) ;
108+ this . $emit ( 'input' , event ) ;
109+ // reset input value
110+ this . $refs . input . value = originalInputValue ;
111+ return ;
112+ }
98113 this . $emit ( 'change' , e ) ;
99114 this . $emit ( 'input' , e ) ;
100115 } ,
@@ -129,7 +144,7 @@ export default {
129144 let suffix = getComponentFromProp ( this , 'suffix' ) ;
130145 if ( suffix || allowClear ) {
131146 return (
132- < span class = { `${ prefixCls } -suffix` } >
147+ < span class = { `${ prefixCls } -suffix` } key = "suffix" >
133148 { this . renderClearIcon ( prefixCls ) }
134149 { suffix }
135150 </ span >
@@ -179,14 +194,18 @@ export default {
179194 return children ;
180195 }
181196 let prefix = getComponentFromProp ( this , 'prefix' ) ;
182- prefix = prefix ? < span class = { `${ prefixCls } -prefix` } > { prefix } </ span > : null ;
197+ prefix = prefix ? (
198+ < span class = { `${ prefixCls } -prefix` } key = "prefix" >
199+ { prefix }
200+ </ span >
201+ ) : null ;
183202
184203 const affixWrapperCls = classNames ( `${ prefixCls } -affix-wrapper` , {
185204 [ `${ prefixCls } -affix-wrapper-sm` ] : size === 'small' ,
186205 [ `${ prefixCls } -affix-wrapper-lg` ] : size === 'large' ,
187206 } ) ;
188207 return (
189- < span class = { affixWrapperCls } >
208+ < span class = { affixWrapperCls } key = "affix" >
190209 { prefix }
191210 { children }
192211 { suffix }
@@ -201,13 +220,14 @@ export default {
201220 'addonAfter' ,
202221 'prefix' ,
203222 'suffix' ,
223+ 'allowClear' ,
204224 'value' ,
205225 'defaultValue' ,
206226 ] ) ;
207227 const { stateValue, getInputClassName, handleKeyDown, handleChange, $listeners } = this ;
208228 const inputProps = {
209229 domProps : {
210- value : stateValue ,
230+ value : fixControlledValue ( stateValue ) ,
211231 } ,
212232 attrs : { ...otherProps , ...this . $attrs } ,
213233 on : {
@@ -218,6 +238,7 @@ export default {
218238 } ,
219239 class : getInputClassName ( prefixCls ) ,
220240 ref : 'input' ,
241+ key : 'ant-input' ,
221242 } ;
222243 if ( $listeners [ 'change.value' ] ) {
223244 inputProps . directives = [ { name : 'ant-input' } ] ;
0 commit comments