Skip to content

Commit

Permalink
fix: input type file cannot assign value
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Nov 9, 2023
1 parent baf2267 commit 7a9bda1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utils/commonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<E>);
return;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ describe('Input', () => {
it('support bigint type', () => {
expect(<Input value={BigInt('2222')} />).toBeTruthy();
});

it('should be compatible with type="file"', () => {
const onChange = jest.fn();
const { container } = render(<Input type="file" onChange={onChange} />);
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 : <input type="file" data-testid="fileInput" />
fireEvent.change(inputEl, {
target: { files: [file] },
});
});
});

describe('should support showCount', () => {
Expand Down

0 comments on commit 7a9bda1

Please sign in to comment.