From cac19d3130adb3be965c0c851a4eceb13bff93ec Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Fri, 9 Aug 2024 15:59:37 -0400 Subject: [PATCH] Added focus on render for keyboard navigation --- Client/src/Components/Inputs/Field/index.jsx | 255 ++++++++++--------- Client/src/Pages/Auth/Login.jsx | 20 +- 2 files changed, 151 insertions(+), 124 deletions(-) diff --git a/Client/src/Components/Inputs/Field/index.jsx b/Client/src/Components/Inputs/Field/index.jsx index 6fb8ea612..0b2fe56fe 100644 --- a/Client/src/Components/Inputs/Field/index.jsx +++ b/Client/src/Components/Inputs/Field/index.jsx @@ -12,7 +12,7 @@ import Visibility from "@mui/icons-material/Visibility"; import ContentCopyIcon from "@mui/icons-material/ContentCopy"; import Button from "../../Button"; import "./index.css"; -import { useState } from "react"; +import { forwardRef, useState } from "react"; /** * @param {Object} props @@ -30,140 +30,151 @@ import { useState } from "react"; * @param {function} props.onChange - Function called on input change. * @param {string} [props.error] - Error message to display for the input field. * @param {boolean} [props.disabled] - Indicates if the input field is disabled. + * @param {React.Ref} [ref] - Ref forwarded to the underlying `TextField` component. Allows for direct interactions such as focusing. */ -const Field = ({ - type = "text", - id, - label, - https, - isRequired, - isOptional, - optionalLabel, - hasCopy, - autoComplete, - placeholder, - value, - onChange, - error, - disabled, -}) => { - const theme = useTheme(); +const Field = forwardRef( + ( + { + type = "text", + id, + label, + https, + isRequired, + isOptional, + optionalLabel, + hasCopy, + autoComplete, + placeholder, + value, + onChange, + error, + disabled, + }, + ref + ) => { + const theme = useTheme(); - // TODO - are we using this feature anywhere ? - const [copy, setCopy] = useState(false); - const handleCopy = () => { - setCopy(true); - setTimeout(() => setCopy(false), 1000); - }; + // TODO - are we using this feature anywhere ? + const [copy, setCopy] = useState(false); + const handleCopy = () => { + setCopy(true); + setTimeout(() => setCopy(false), 1000); + }; - const [isVisible, setVisible] = useState(false); + const [isVisible, setVisible] = useState(false); - return ( - - {label && ( - - {label} - {isRequired ? * : ""} - {isOptional ? ( - - {optionalLabel || "(optional)"} - - ) : ( - "" - )} - - )} - - - {https ? "https" : "http"}:// - - - ), - endAdornment: - type === "password" ? ( - - setVisible((show) => !show)} - tabIndex={-1} - sx={{ - color: theme.palette.section.borderColor, - padding: `calc(${theme.gap.xs} / 2)`, - "&:focus": { - outline: "none", - }, - "& .MuiTouchRipple-root": { - pointerEvents: "none", - display: "none", - }, - }} - > - {!isVisible ? : } - - + return ( + + {label && ( + + {label} + {isRequired ? * : ""} + {isOptional ? ( + + {optionalLabel || "(optional)"} + ) : ( - hasCopy && ( - -