import React, { FocusEvent, InputHTMLAttributes, RefObject } from 'react' import { useRecoilState } from 'recoil' import { appState } from '../../store/Atoms' const TextInput = React.forwardRef< HTMLInputElement, InputHTMLAttributes >((props, ref) => { const { onFocus, onBlur, ...itemProps } = props const [_, setAppState] = useRecoilState(appState) const handleOnFocus = (evt: FocusEvent) => { setAppState(old => { return { ...old, disableShortCuts: true } }) onFocus?.(evt) } const handleOnBlur = (evt: FocusEvent) => { setAppState(old => { return { ...old, disableShortCuts: false } }) onBlur?.(evt) } return ( evt.stopPropagation()} onKeyDown={e => { if (e.key === 'Escape') { e.currentTarget.blur() } if ((e.ctrlKey || e.metaKey) && e.key === 'z') { e.stopPropagation() } }} /> ) }) export default TextInput