Skip to content

Commit

Permalink
feat: keyLockRef
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyair committed Jul 18, 2024
1 parent 2e9c8e7 commit 63b5cba
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {

const [focused, setFocused] = useState<boolean>(false);
const compositionRef = useRef(false);
const enterRef = useRef(false);
const keyLockRef = useRef(false);

const inputRef = useRef<HTMLInputElement>(null);
const holderRef = useRef<HolderRef>(null);
Expand Down Expand Up @@ -158,15 +158,15 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {

const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
onKeyDown?.(e);
if (onPressEnter && e.key === 'Enter' && !enterRef.current) {
enterRef.current = true;
if (onPressEnter && e.key === 'Enter' && !keyLockRef.current) {
keyLockRef.current = true;
onPressEnter(e);
}
};
const handleKeyUp = (e: React.KeyboardEvent<HTMLInputElement>) => {
onKeyUp?.(e);
if (e.key === 'Enter') {
enterRef.current = false;
keyLockRef.current = false;
}
};

Expand Down

0 comments on commit 63b5cba

Please sign in to comment.