From 2996058fa257f3e4ba4fccb1d814cec508fdf122 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Thu, 24 Oct 2024 09:12:49 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=98=20a11y:=20Switch=20Contrast=20and?= =?UTF-8?q?=20File=20Input=20Key=20Events=20to=20WCAG=20(#4536)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🔘 a11y: Improve Contrast of Switch/Toggles to WCAG Standard * refactor: Improve file attachment accessibility in Chat Input component * refactor: clear input ref value before clicks --- .../Chat/Input/Files/AttachFile.tsx | 26 +++++++-- client/src/components/ui/FileUpload.tsx | 54 +++++++------------ client/src/components/ui/Switch.tsx | 2 +- client/src/style.css | 2 + client/tailwind.config.cjs | 1 + 5 files changed, 46 insertions(+), 39 deletions(-) diff --git a/client/src/components/Chat/Input/Files/AttachFile.tsx b/client/src/components/Chat/Input/Files/AttachFile.tsx index 49e5c650de4..206048870d1 100644 --- a/client/src/components/Chat/Input/Files/AttachFile.tsx +++ b/client/src/components/Chat/Input/Files/AttachFile.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useRef } from 'react'; import { FileUpload, TooltipAnchor } from '~/components/ui'; import { AttachmentIcon } from '~/components/svg'; import { useLocalize } from '~/hooks'; @@ -14,19 +14,37 @@ const AttachFile = ({ handleFileChange: (event: React.ChangeEvent) => void; }) => { const localize = useLocalize(); + const inputRef = useRef(null); const isUploadDisabled = disabled ?? false; return ( - + { + if (!inputRef.current) { + return; + } + if (e.key === 'Enter' || e.key === ' ') { + inputRef.current.value = ''; + inputRef.current.click(); + } + }} + onClick={() => { + if (!inputRef.current) { + return; + } + inputRef.current.value = ''; + inputRef.current.click(); + }} >
diff --git a/client/src/components/ui/FileUpload.tsx b/client/src/components/ui/FileUpload.tsx index f7f6976797a..3481a36e8ed 100644 --- a/client/src/components/ui/FileUpload.tsx +++ b/client/src/components/ui/FileUpload.tsx @@ -1,43 +1,29 @@ -import React, { useRef } from 'react'; +import React, { forwardRef } from 'react'; type FileUploadProps = { - handleFileChange: (event: React.ChangeEvent) => void; - onClick?: () => void; className?: string; + onClick?: () => void; children: React.ReactNode; + handleFileChange: (event: React.ChangeEvent) => void; }; -const FileUpload: React.FC = ({ - handleFileChange, - children, - onClick, - className = '', -}) => { - const fileInputRef = useRef(null); - - const handleButtonClick = () => { - if (onClick) { - onClick(); - } - // necessary to reset the input - if (fileInputRef.current) { - fileInputRef.current.value = ''; - } - fileInputRef.current?.click(); - }; +const FileUpload = forwardRef( + ({ children, handleFileChange }, ref) => { + return ( + <> + {children} + + + ); + }, +); - return ( -
- {children} - -
- ); -}; +FileUpload.displayName = 'FileUpload'; export default FileUpload; diff --git a/client/src/components/ui/Switch.tsx b/client/src/components/ui/Switch.tsx index f24e7edd51e..8145901c7ab 100644 --- a/client/src/components/ui/Switch.tsx +++ b/client/src/components/ui/Switch.tsx @@ -8,7 +8,7 @@ const Switch = React.forwardRef< >(({ className, ...props }, ref) => (