diff --git a/src/components/AttachmentPicker/index.tsx b/src/components/AttachmentPicker/index.tsx index 669b26724a02..26d117697888 100644 --- a/src/components/AttachmentPicker/index.tsx +++ b/src/components/AttachmentPicker/index.tsx @@ -1,4 +1,5 @@ import React, {useRef} from 'react'; +import type {ValueOf} from 'type-fest'; import Visibility from '@libs/Visibility'; import CONST from '@src/CONST'; import type AttachmentPickerProps from './types'; @@ -14,6 +15,25 @@ function getAcceptableFileTypes(type: string): string | undefined { return 'image/*'; } +function getAcceptableFileTypesFromAList(fileTypes: Array>): string { + const acceptValue = fileTypes + .map((type) => { + switch (type) { + case 'msword': + return 'application/msword'; + case 'text': + return 'text/plain'; + case 'message': + return 'message/rfc822'; + default: + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions + return `.${type}`; + } + }) + .join(','); + return acceptValue; +} + /** * This component renders a function as a child and * returns a "show attachment picker" method that takes @@ -21,7 +41,7 @@ function getAcceptableFileTypes(type: string): string | undefined { * on a Browser we must append a hidden input to the DOM * and listen to onChange event. */ -function AttachmentPicker({children, type = CONST.ATTACHMENT_PICKER_TYPE.FILE}: AttachmentPickerProps): React.JSX.Element { +function AttachmentPicker({children, type = CONST.ATTACHMENT_PICKER_TYPE.FILE, acceptedFileTypes}: AttachmentPickerProps): React.JSX.Element { const fileInput = useRef(null); const onPicked = useRef<(file: File) => void>(() => {}); const onCanceled = useRef<() => void>(() => {}); @@ -75,7 +95,7 @@ function AttachmentPicker({children, type = CONST.ATTACHMENT_PICKER_TYPE.FILE}: {once: true}, ); }} - accept={getAcceptableFileTypes(type)} + accept={acceptedFileTypes ? getAcceptableFileTypesFromAList(acceptedFileTypes) : getAcceptableFileTypes(type)} /> {children({ openPicker: ({onPicked: newOnPicked, onCanceled: newOnCanceled = () => {}}) => { diff --git a/src/components/AttachmentPicker/types.ts b/src/components/AttachmentPicker/types.ts index 445d79bce07a..057ec72de27e 100644 --- a/src/components/AttachmentPicker/types.ts +++ b/src/components/AttachmentPicker/types.ts @@ -40,6 +40,8 @@ type AttachmentPickerProps = { /** The types of files that can be selected with this picker. */ type?: ValueOf; + + acceptedFileTypes?: Array>; }; export default AttachmentPickerProps; diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index faf67efa857d..f20417671a6d 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -590,7 +590,7 @@ function IOURequestStepScan({ - + {({openPicker}) => (