import React, { FC, memo, useCallback, useRef, } from '../../lib/teact/teact'; import { formatCardExpiry } from '../middle/helpers/inputFormatters'; import InputText from '../ui/InputText'; const MAX_FIELD_LENGTH = 5; export type OwnProps = { value: string; error?: string; onChange: (value: string) => void; }; const ExpiryInput : FC = ({ value, error, onChange }) => { // eslint-disable-next-line no-null/no-null const expiryInputRef = useRef(null); const handleKeyDown = useCallback((e) => { if (e.key === 'Backspace' && value.charAt(value.length - 1) === '/') { const newValue = value.slice(0, value.length - 1); if (expiryInputRef.current) { expiryInputRef.current.value = newValue; } } }, [value]); const handleChange = useCallback((e) => { onChange(formatCardExpiry(e.target.value)); }, [onChange]); return ( ); }; export default memo(ExpiryInput);