import { Stack, Typography } from "@mui/material"; import Field from "../Components/Inputs/Field"; import TextInput from "../Components/Inputs/TextInput"; import { useState, useEffect, useRef } from "react"; import { HttpAdornment } from "../Components/Inputs/TextInput/Adornments"; import { PasswordEndAdornment } from "../Components/Inputs/TextInput/Adornments"; const Test = () => { const [originalValue, setOriginalValue] = useState(""); const [originalError, setOriginalError] = useState(""); const [newValue, setNewValue] = useState(""); const [newError, setNewError] = useState(""); const [thresholdValue, setThresholdValue] = useState(20); const [thresholdError, setThresholdError] = useState(""); const [thresholdValue2, setThresholdValue2] = useState(20); const [thresholdError2, setThresholdError2] = useState(""); const inputRef = useRef(null); useEffect(() => { if (inputRef.current) { inputRef.current.focus(); } }, []); const checkError = (value) => { if (value !== "clear") { return "This is an error"; } return ""; }; const checkThresholdError = (value) => { if (value !== 99) { return "This is a threshold error"; } return ""; }; const checkThresholdError2 = (value) => { if (value !== 99) { return "This is a threshold error 2"; } return ""; }; const handleOriginalValue = (e) => { setOriginalError(checkError(e.target.value)); setOriginalValue(e.target.value); }; const handleNewValue = (e) => { setNewError(checkError(e.target.value)); setNewValue(e.target.value); }; const handleThresholdValue = (e) => { const parsedVal = parseInt(e.target.value); setThresholdError(checkThresholdError(parsedVal)); setThresholdValue(parsedVal); }; const handleThresholdValue2 = (e) => { const parsedVal = parseInt(e.target.value); setThresholdError2(checkThresholdError2(parsedVal)); setThresholdValue2(parsedVal); }; return ( This is a test page for the TextInput component. It is a rationalized Input component. Type anything for an error. Typing "clear" will clear the error for text based input Typing "99" will clear the error for threshold based input } onChange={handleNewValue} error={newError !== ""} helperText={newError} /> } onChange={handleNewValue} error={newError !== ""} helperText={newError} ref={inputRef} /> Short field for threshold. Easily show/hide error text {thresholdError} {thresholdError2} ); }; export default Test;