Skip to content

Commit 2133695

Browse files
authored
fix: input type file cannot assign value (#53)
* fix: input type file cannot assign value * fix: father is missing
1 parent baf2267 commit 2133695

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"cross-env": "^7.0.2",
6262
"dumi": "^2.1.14",
6363
"eslint": "^7.0.0",
64-
"father": "^4",
64+
"father": "^4.3.7",
6565
"gh-pages": "^3.1.0",
6666
"husky": "^8.0.1",
6767
"less": "^3.10.3",

src/utils/commonUtils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ export function resolveOnChange<
5757
target: { value: target },
5858
currentTarget: { value: target },
5959
});
60-
61-
target.value = targetValue;
60+
// https://github.com/ant-design/ant-design/issues/45737
61+
if (target.type !== 'file') {
62+
target.value = targetValue;
63+
}
6264
onChange(event as React.ChangeEvent<E>);
6365
return;
6466
}

tests/index.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ describe('Input', () => {
7979
it('support bigint type', () => {
8080
expect(<Input value={BigInt('2222')} />).toBeTruthy();
8181
});
82+
83+
it('should be compatible with type="file"', () => {
84+
const onChange = jest.fn();
85+
const { container } = render(<Input type="file" onChange={onChange} />);
86+
const inputEl = container.querySelector('input')!;
87+
const file = new File(['(⌐□_□)'], 'file.xml', { type: 'application/xml' });
88+
// upload the file by updating the value attribute of the input
89+
// I assume : <input type="file" data-testid="fileInput" />
90+
fireEvent.change(inputEl, {
91+
target: { files: [file] },
92+
});
93+
});
8294
});
8395

8496
describe('should support showCount', () => {

0 commit comments

Comments
 (0)