import React, { useRef } from 'react'; interface MaxMinLenAttrIntr { maxLength: number; minLength: number; handlePropertyChange: (changeTo: string, changeWith: string | boolean | number) => void; } const MaxMinLenAttr: React.FC = ({ maxLength, minLength, handlePropertyChange }) => { const firstChangedField = useRef(null); const handleMaxChange = (e: React.ChangeEvent) => { const newMax = Number(e.target.value); if (!firstChangedField.current) { firstChangedField.current = 'maxLength'; } if (firstChangedField.current === 'minLength' && newMax < minLength) { alert(`Max Length must be greater than or equal to Min Length (${minLength})`); return; } handlePropertyChange('maxLength', newMax); }; const handleMinChange = (e: React.ChangeEvent) => { const newMin = Number(e.target.value); if (!firstChangedField.current) { firstChangedField.current = 'minLength'; } if (firstChangedField.current === 'maxLength' && newMin > maxLength) { alert(`Min Length must be less than or equal to Max Length (${maxLength})`); return; } handlePropertyChange('minLength', newMin); }; return ( <>
); }; export default MaxMinLenAttr;