From 7a9bda153a6f9707c4ef01e26dfd5cd751090ad7 Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 9 Nov 2023 12:08:19 +0800 Subject: [PATCH] fix: input type file cannot assign value --- src/utils/commonUtils.ts | 6 ++++-- tests/index.test.tsx | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/utils/commonUtils.ts b/src/utils/commonUtils.ts index a1a9e30..7d9eadd 100644 --- a/src/utils/commonUtils.ts +++ b/src/utils/commonUtils.ts @@ -57,8 +57,10 @@ export function resolveOnChange< target: { value: target }, currentTarget: { value: target }, }); - - target.value = targetValue; + // https://github.com/ant-design/ant-design/issues/45737 + if (target.type !== 'file') { + target.value = targetValue; + } onChange(event as React.ChangeEvent); return; } diff --git a/tests/index.test.tsx b/tests/index.test.tsx index 44a7bfa..2a88538 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -79,6 +79,18 @@ describe('Input', () => { it('support bigint type', () => { expect().toBeTruthy(); }); + + it('should be compatible with type="file"', () => { + const onChange = jest.fn(); + const { container } = render(); + const inputEl = container.querySelector('input')!; + const file = new File(['(⌐□_□)'], 'file.xml', { type: 'application/xml' }); + // upload the file by updating the value attribute of the input + // I assume : + fireEvent.change(inputEl, { + target: { files: [file] }, + }); + }); }); describe('should support showCount', () => {