File tree Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -6,19 +6,30 @@ export const restrictNumericInput = (e: React.KeyboardEvent<HTMLInputElement>) =
6
6
const inputValue = inputElement . value ;
7
7
8
8
const allowedControlKeys = [
9
- 'Backspace' ,
10
- 'ArrowUp' ,
11
- 'ArrowDown' ,
12
- 'ArrowLeft' ,
13
- 'ArrowRight' ,
14
- 'Control' ,
9
+ 'backspace' ,
10
+ 'arrowup' ,
11
+ 'arrowdown' ,
12
+ 'arrowleft' ,
13
+ 'arrowright' ,
14
+ 'control' ,
15
+ 'meta' ,
15
16
'v' ,
16
17
'c' ,
18
+ 'tab' ,
19
+ 'shift' ,
20
+ 'delete'
17
21
] ;
18
22
23
+ // Convert key to lowercase for consistent checking
24
+ const lowerKey = key . toLowerCase ( ) ;
25
+
26
+ // Check if it's a copy/paste command (Windows: Ctrl, Mac: Command)
27
+ const isCopyPaste = ( e . ctrlKey || e . metaKey ) && ( lowerKey === 'c' || lowerKey === 'v' ) ;
28
+
19
29
if (
20
- ( key === 'e' || key === 'E' || ( isNaN ( Number ( key ) ) && key !== '.' && ! allowedControlKeys . includes ( key ) ) )
21
- && ! ( e . ctrlKey && ( key === 'v' || key === 'c' ) )
30
+ ( lowerKey === 'e' ||
31
+ ( isNaN ( Number ( key ) ) && key !== '.' && ! allowedControlKeys . includes ( lowerKey ) ) )
32
+ && ! isCopyPaste
22
33
) {
23
34
e . preventDefault ( ) ;
24
35
}
You can’t perform that action at this time.
0 commit comments