-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Upload] File upload button not keyboard accessible #22141
Comments
I can't reproduce the issue on Ubuntu 18.04.4 LTS with neither Chrome Version 84.0.4147.105 (Official Build) (64-bit) nor Firefox 79.0. Tried it with my existing profile and a new one. Maybe some extension is interfering? Can you reproduce this in an incognito tab (or preferably with a new user profile). It could be caused by a setting in your operating system. In the end user agents decide what elements are keyboard focusable and which aren't. This is not defined universally in a web standard. |
The problem is not about focusability, but about opening the file selection dialog.
With a vanilla |
That makes sense, thanks for helping me understand. The markup we have documented is fundamentally flawed since the file input won't even be part of the accessibility tree. I don't have an easy solution to fix this right now. A standalone component that keeps the focus on |
Something like https://codesandbox.io/s/e2kv9?file=/demo.js seems viable. Misses color styles and focus-visible specific styling. But keyboard accessibility and |
Should we use this issue as an opportunity to work on a dedicated upload component? At least, if we don't find a simple solution. Ant Design seems to solve the problem by manually triggering the file input https://github.com/react-component/upload/blob/master/src/AjaxUploader.jsx#L32. I have been collecting comparison points for the Upload component at https://trello.com/c/uKckCoKm/1709-dropzone-upload-component. |
Closing in favor of https://github.com/mui/material-ui/issues/22434. A dedicated component would fix existing usages which we can't really do with demos. |
The upload button example is completely inaccessible by anyone that is not using a mouse. It lacks both support for keyboard interaction and drag-and-drop, as well as not appearing in the accessibility tree. See mui#22141 for a more detailed discussion of the issue.
The upload button example is completely inaccessible by anyone that is not using a mouse. It lacks both support for keyboard interaction and drag-and-drop, as well as not appearing in the accessibility tree. See mui#22141 for a more detailed discussion of the issue.
If anyone is still having this problem, here's a solution for you. export const FileInput = forwardRef((props: IFileInput, ref) => {
const inputElementRef = useRef<HTMLInputElement>()
const {
label,
} = props;
return (
<Box ref={ref} >
<Button
onKeyDownCapture={e => {
if (!acceptableTriggerKeyCodes.includes(e.code)) return;
inputElementRef.current.click()
}}
htmlFor={label}
component="label"
>
{label}
<input
ref={inputElementRef}
id={label}
hidden
type="file"
/>
</Button>
</Box>
);
}); You can use the component with any validation library and it will trigger the input upload against clicks and key events as well. |
Thank you @mshahzebraza, this is what we needed onKeyDown={(event) => {
if (['Enter', 'Space'].includes(event.code)) {
inputRef.current?.click();
}
}} |
--> There is this related issue, but the discussion ended up shifting away from the file upload button.
Current Behavior 😯
Following the official file upload button example, once one of the upload button is keyboard focused, pressing on
enter
or thespacebar
does not do anything.Expected Behavior 🤔
Following the official file upload button example, once one of the upload button is keyboard focused, pressing on
enter
or thespacebar
should open the file selection dialog.Steps to Reproduce 🕹
Steps:
browser
part of the window.tab
once or twice (to respectively select the first or the second button).enter
orspacebar
, nothing happens.Context 🔦
This is an accessibility requirement: https://webaim.org/techniques/keyboard/#testing
Your Environment 🌎
The text was updated successfully, but these errors were encountered: