Set `accept` attribute to `image/*` in ImageUpload (#989)
authorStefano Pigozzi <me@steffo.eu>
Sun, 15 Jan 2023 04:14:16 +0000 (05:14 +0100)
committerGitHub <noreply@github.com>
Sun, 15 Jan 2023 04:14:16 +0000 (09:44 +0530)
That way, browsers will suggest to the users to upload an image file instead of any kind of file.

The behaviour is in-line with Element's, which specifies the same attribute when selecting an avatar.

Please note that it does not prevent users from uploading non-image files as avatars, as browsers interpret that attribute as a mere suggestion, which can be bypassed in the file select dialog.

Partially fixes #982.

src/app/molecules/image-upload/ImageUpload.jsx

index 34d0d4be1cf3cb54b2f7ef5be341b5b78a3ebfa0..53fc7e161bfdd95b552116bd33c4a6fd105dae03 100644 (file)
@@ -74,7 +74,7 @@ function ImageUpload({
           <Text variant="b3">{uploadPromise ? 'Cancel' : 'Remove'}</Text>
         </button>
       )}
-      <input onChange={uploadImage} style={{ display: 'none' }} ref={uploadImageRef} type="file" />
+      <input onChange={uploadImage} style={{ display: 'none' }} ref={uploadImageRef} type="file" accept="image/*" />
     </div>
   );
 }