Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 15829x 17301x 17301x 1177x 147x 17301x 9x 17301x | import React from "react";
import type { InputHandler } from "~components/input";
import { emptyInputHandler } from "~components/input.base";
export const useAutofocus = ({ shouldFocus }: { shouldFocus: boolean }) => {
const ref = React.useRef<InputHandler>(emptyInputHandler);
React.useEffect(() => {
Iif (!shouldFocus) {
return;
}
ref.current.focus();
}, [shouldFocus]);
const onKeyDownBlur = React.useCallback((key: string) => {
Iif (key === "Escape" || key === "Enter") {
ref.current.blur();
}
}, []);
return { ref, onKeyDownBlur };
};
|