-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔘 a11y: Switch Contrast and File Input Key Events to WCAG (#4536)
* 🔘 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
- Loading branch information
1 parent
655f637
commit 2996058
Showing
5 changed files
with
46 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,29 @@ | ||
import React, { useRef } from 'react'; | ||
import React, { forwardRef } from 'react'; | ||
|
||
type FileUploadProps = { | ||
handleFileChange: (event: React.ChangeEvent<HTMLInputElement>) => void; | ||
onClick?: () => void; | ||
className?: string; | ||
onClick?: () => void; | ||
children: React.ReactNode; | ||
handleFileChange: (event: React.ChangeEvent<HTMLInputElement>) => void; | ||
}; | ||
|
||
const FileUpload: React.FC<FileUploadProps> = ({ | ||
handleFileChange, | ||
children, | ||
onClick, | ||
className = '', | ||
}) => { | ||
const fileInputRef = useRef<HTMLInputElement>(null); | ||
|
||
const handleButtonClick = () => { | ||
if (onClick) { | ||
onClick(); | ||
} | ||
// necessary to reset the input | ||
if (fileInputRef.current) { | ||
fileInputRef.current.value = ''; | ||
} | ||
fileInputRef.current?.click(); | ||
}; | ||
const FileUpload = forwardRef<HTMLInputElement, FileUploadProps>( | ||
({ children, handleFileChange }, ref) => { | ||
return ( | ||
<> | ||
{children} | ||
<input | ||
ref={ref} | ||
multiple | ||
type="file" | ||
style={{ display: 'none' }} | ||
onChange={handleFileChange} | ||
/> | ||
</> | ||
); | ||
}, | ||
); | ||
|
||
return ( | ||
<div onClick={handleButtonClick} style={{ cursor: 'pointer' }} className={className}> | ||
{children} | ||
<input | ||
ref={fileInputRef} | ||
multiple | ||
type="file" | ||
style={{ display: 'none' }} | ||
onChange={handleFileChange} | ||
/> | ||
</div> | ||
); | ||
}; | ||
FileUpload.displayName = 'FileUpload'; | ||
|
||
export default FileUpload; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters