diff --git a/packages/Form/Input/file/src/File.tsx b/packages/Form/Input/file/src/File.tsx index ac6d12b90..d49a3ada9 100644 --- a/packages/Form/Input/file/src/File.tsx +++ b/packages/Form/Input/file/src/File.tsx @@ -67,7 +67,9 @@ const File = ({ ); }; -export type CustomFile = { +export type FilePreview = File & { preview: string }; + +export type CustomFile = { id: string; file: T; }; @@ -89,11 +91,31 @@ const handlers = { ) => { const values = acceptedFiles.map((file) => ({ id: createId(), - file: { ...file, preview: URL.createObjectURL(file) }, + file: { + ...file, + lastModified: file.lastModified, + name: file.name, + type: file.type, + size: file.size, + stream: file.stream, + arrayBuffer: file.arrayBuffer, + slice: file.slice, + text: file.text, + preview: URL.createObjectURL(file), + }, })); const errors = rejectedFiles.map((error) => ({ id: createId(), - file: error, + file: { + errors: error.errors, + file: { + ...error.file, + lastModified: error.file.lastModified, + name: error.file.name, + type: error.file.type, + size: error.file.size, + } as File, + }, })); onChange && onChange({ diff --git a/packages/Form/Input/file/src/__tests__/FileLine.spec.tsx b/packages/Form/Input/file/src/__tests__/FileLine.spec.tsx index 170482d95..414b2b091 100644 --- a/packages/Form/Input/file/src/__tests__/FileLine.spec.tsx +++ b/packages/Form/Input/file/src/__tests__/FileLine.spec.tsx @@ -2,12 +2,20 @@ import React from 'react'; import { render, fireEvent } from '@testing-library/react'; import FileLine, { Preview } from '../FileLine'; +import { FilePreview } from '../File'; describe('', () => { it('renders File.FileInput correctly', () => { const { asFragment } = render( ); @@ -18,7 +26,14 @@ describe('', () => { const { getByRole } = render( @@ -35,7 +50,7 @@ describe('', () => { preview: '', size: 2, }; - const { asFragment } = render(); + const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); it('renders Preview correctly for other type', () => { @@ -46,7 +61,7 @@ describe('', () => { preview: '', size: 2, }; - const { asFragment } = render(); + const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); }); diff --git a/packages/Form/Input/file/src/__tests__/FileTable.spec.tsx b/packages/Form/Input/file/src/__tests__/FileTable.spec.tsx index 9f29e6531..6279a429f 100644 --- a/packages/Form/Input/file/src/__tests__/FileTable.spec.tsx +++ b/packages/Form/Input/file/src/__tests__/FileTable.spec.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { render } from '@testing-library/react'; import FileTable from '../FileTable'; +import { FilePreview } from '../File'; describe('', () => { it('renders File.FileTable correctly', () => { @@ -12,7 +13,7 @@ describe('', () => { ...new File([], 'youhou.txt'), name: 'youhou.txt', size: 2, - }, + } as File, errors: [], }, ]} @@ -23,7 +24,7 @@ describe('', () => { name: 'superfile.pdf', preview: '', size: 2, - }, + } as FilePreview, id: 'id', }, ]} @@ -41,7 +42,7 @@ describe('', () => { ...new File([], 'youhou.txt'), name: 'youhou.txt', size: 2, - }, + } as File, errors: [], }, ]} @@ -63,7 +64,7 @@ describe('', () => { name: 'youhou.txt', size: 2, preview: '', - }, + } as FilePreview, id: 'id', }, ]}