File tree Expand file tree Collapse file tree 4 files changed +42
-2
lines changed Expand file tree Collapse file tree 4 files changed +42
-2
lines changed Original file line number Diff line number Diff line change 44
44
},
45
45
"devDependencies" : {
46
46
"@testing-library/jest-dom" : " ^5.16.4" ,
47
- "@testing-library/react" : " 13.3.0" ,
47
+ "@testing-library/react" : " ^ 13.3.0" ,
48
48
"@types/classnames" : " ^2.2.9" ,
49
49
"@types/enzyme" : " ^3.10.8" ,
50
50
"@types/jest" : " ^26.0.0" ,
Original file line number Diff line number Diff line change @@ -444,6 +444,11 @@ const InputNumber = React.forwardRef(
444
444
}
445
445
} ;
446
446
447
+ // Solve the issue of the event triggering sequence when entering numbers in chinese input (Safari)
448
+ const onBeforeInput = ( ) => {
449
+ userTypingRef . current = true ;
450
+ } ;
451
+
447
452
const onKeyDown : React . KeyboardEventHandler < HTMLInputElement > = ( event ) => {
448
453
const { which, shiftKey } = event ;
449
454
userTypingRef . current = true ;
@@ -536,6 +541,7 @@ const InputNumber = React.forwardRef(
536
541
onKeyUp = { onKeyUp }
537
542
onCompositionStart = { onCompositionStart }
538
543
onCompositionEnd = { onCompositionEnd }
544
+ onBeforeInput = { onBeforeInput }
539
545
>
540
546
{ controls && (
541
547
< StepHandler
Original file line number Diff line number Diff line change 1
1
import InputNumber , { InputNumberProps } from './InputNumber' ;
2
2
3
- export { InputNumberProps } ;
3
+ export type { InputNumberProps } ;
4
4
5
5
export default InputNumber ;
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import '@testing-library/jest-dom' ;
3
+ import { render , fireEvent } from '@testing-library/react' ;
4
+ import KeyCode from 'rc-util/lib/KeyCode' ;
5
+ import InputNumber from '../src' ;
6
+
7
+ describe ( 'InputNumber.Precision' , ( ) => {
8
+ // https://github.com/react-component/input-number/issues/506
9
+ it ( 'Safari bug of input' , async ( ) => {
10
+ const Demo = ( ) => {
11
+ const [ value , setValue ] = React . useState < string | number > ( null ) ;
12
+
13
+ return < InputNumber precision = { 2 } value = { value } onChange = { setValue } /> ;
14
+ } ;
15
+
16
+ const { container } = render ( < Demo /> ) ;
17
+ const input = container . querySelector ( 'input' ) ;
18
+
19
+ // React use SyntheticEvent to handle `onBeforeInput`, let's mock this
20
+ fireEvent . keyPress ( input , {
21
+ which : KeyCode . TWO ,
22
+ keyCode : KeyCode . TWO ,
23
+ char : '2' ,
24
+ } ) ;
25
+
26
+ fireEvent . change ( input , {
27
+ target : {
28
+ value : '2' ,
29
+ } ,
30
+ } ) ;
31
+
32
+ expect ( input . value ) . toEqual ( '2' ) ;
33
+ } ) ;
34
+ } ) ;
You can’t perform that action at this time.
0 commit comments