Skip to content

Commit

Permalink
fix: input type file cannot assign value (#53)
Browse files Browse the repository at this point in the history
* fix: input type file cannot assign value

* fix: father is missing
  • Loading branch information
afc163 authored Nov 9, 2023
1 parent baf2267 commit 2133695
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"cross-env": "^7.0.2",
"dumi": "^2.1.14",
"eslint": "^7.0.0",
"father": "^4",
"father": "^4.3.7",
"gh-pages": "^3.1.0",
"husky": "^8.0.1",
"less": "^3.10.3",
Expand Down
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 2133695

Please sign in to comment.