close button dialog
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useEffect } from "react";
|
||||
function usePersianInput(inputRef, onChange) {
|
||||
useEffect(() => {
|
||||
const input = inputRef.current;
|
||||
@@ -6,7 +6,7 @@ function usePersianInput(inputRef, onChange) {
|
||||
|
||||
const handleInput = (event) => {
|
||||
const originalValue = event.target.value;
|
||||
const filteredValue = originalValue.replace(/[A-Za-z]/g, '');
|
||||
const filteredValue = originalValue.replace(/[A-Za-z]/g, "");
|
||||
if (filteredValue !== originalValue) {
|
||||
event.target.value = filteredValue;
|
||||
if (onChange) {
|
||||
@@ -19,15 +19,15 @@ function usePersianInput(inputRef, onChange) {
|
||||
|
||||
const handleKeyDown = (event) => {
|
||||
const controlKeys = [
|
||||
'Backspace',
|
||||
'Delete',
|
||||
'Tab',
|
||||
'Escape',
|
||||
'Enter',
|
||||
'ArrowLeft',
|
||||
'ArrowRight',
|
||||
'ArrowUp',
|
||||
'ArrowDown'
|
||||
"Backspace",
|
||||
"Delete",
|
||||
"Tab",
|
||||
"Escape",
|
||||
"Enter",
|
||||
"ArrowLeft",
|
||||
"ArrowRight",
|
||||
"ArrowUp",
|
||||
"ArrowDown",
|
||||
];
|
||||
if (controlKeys.includes(event.key)) return;
|
||||
|
||||
@@ -36,14 +36,14 @@ function usePersianInput(inputRef, onChange) {
|
||||
}
|
||||
};
|
||||
|
||||
input.addEventListener('input', handleInput);
|
||||
input.addEventListener('keydown', handleKeyDown);
|
||||
input.addEventListener("input", handleInput);
|
||||
input.addEventListener("keydown", handleKeyDown);
|
||||
|
||||
return () => {
|
||||
input.removeEventListener('input', handleInput);
|
||||
input.removeEventListener('keydown', handleKeyDown);
|
||||
input.removeEventListener("input", handleInput);
|
||||
input.removeEventListener("keydown", handleKeyDown);
|
||||
};
|
||||
}, [inputRef, onChange]);
|
||||
}
|
||||
|
||||
export default usePersianInput;
|
||||
export default usePersianInput;
|
||||
|
||||
Reference in New Issue
Block a user