close button dialog

This commit is contained in:
2025-02-25 11:33:55 +00:00
committed by AmirHossein Mahmoodi
parent 1d9d153657
commit ba464b1376
30 changed files with 221 additions and 63 deletions

View File

@@ -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;