File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 11/* eslint no-console:0 */
2- import React from 'react' ;
32import InputNumber from 'rc-input-number' ;
3+ import React from 'react' ;
44import '../../assets/index.less' ;
55
66export default ( ) => {
@@ -54,6 +54,17 @@ export default () => {
5454 max = { 99 }
5555 defaultValue = { 33 }
5656 />
57+
58+ < hr />
59+ < h3 > !changeOnBlur</ h3 >
60+ < InputNumber
61+ style = { { width : 100 } }
62+ min = { - 9 }
63+ max = { 9 }
64+ defaultValue = { 10 }
65+ onChange = { onChange }
66+ changeOnBlur = { false }
67+ />
5768 </ div >
5869 ) ;
5970} ;
Original file line number Diff line number Diff line change @@ -102,7 +102,11 @@ export interface InputNumberProps<T extends ValueType = ValueType>
102102 // focusOnUpDown: boolean;
103103 // useTouch: boolean;
104104
105- // size?: ISize;
105+ /**
106+ * Trigger change onBlur event.
107+ * If disabled, user must press enter or click handler to confirm the value update
108+ */
109+ changeOnBlur ?: boolean ;
106110}
107111
108112type InternalInputNumberProps = Omit < InputNumberProps , 'prefix' | 'suffix' > ;
@@ -138,6 +142,8 @@ const InternalInputNumber = React.forwardRef(
138142 onPressEnter,
139143 onStep,
140144
145+ changeOnBlur = true ,
146+
141147 ...inputProps
142148 } = props ;
143149
@@ -513,7 +519,9 @@ const InternalInputNumber = React.forwardRef(
513519
514520 // >>> Focus & Blur
515521 const onBlur = ( ) => {
516- flushInputValue ( false ) ;
522+ if ( changeOnBlur ) {
523+ flushInputValue ( false ) ;
524+ }
517525
518526 setFocus ( false ) ;
519527
Original file line number Diff line number Diff line change @@ -212,4 +212,15 @@ describe('InputNumber.Input', () => {
212212 expect ( onChange ) . toHaveBeenLastCalledWith ( null ) ;
213213 } ) ;
214214 } ) ;
215+
216+ it ( '!changeOnBlur' , ( ) => {
217+ const onChange = jest . fn ( ) ;
218+
219+ const { container } = render (
220+ < InputNumber min = { 0 } max = { 9 } defaultValue = { 10 } changeOnBlur = { false } onChange = { onChange } /> ,
221+ ) ;
222+
223+ fireEvent . blur ( container . querySelector ( 'input' ) ) ;
224+ expect ( onChange ) . not . toHaveBeenCalled ( ) ;
225+ } ) ;
215226} ) ;
You can’t perform that action at this time.
0 commit comments