Skip to content

Commit 99cdc3e

Browse files
authored
Revert "feat: support name prop (#574)" (#575)
1 parent d3cdcb0 commit 99cdc3e

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/AjaxUploader.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ class AjaxUploader extends Component<UploadProps> {
269269
classNames = {},
270270
disabled,
271271
id,
272-
name,
273272
style,
274273
styles = {},
275274
multiple,
@@ -308,7 +307,6 @@ class AjaxUploader extends Component<UploadProps> {
308307
<input
309308
{...pickAttrs(otherProps, { aria: true, data: true })}
310309
id={id}
311-
name={name}
312310
disabled={disabled}
313311
type="file"
314312
ref={this.saveFileInput}

src/Upload.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Upload extends Component<UploadProps> {
1111
prefixCls: 'rc-upload',
1212
data: {},
1313
headers: {},
14+
name: 'file',
1415
multipart: false,
1516
onStart: empty,
1617
onError: empty,

tests/uploader.spec.tsx

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,6 @@ describe('uploader', () => {
152152
expect(container.querySelector('input')!.id).toBe('bamboo');
153153
});
154154

155-
// https://github.com/ant-design/ant-design/issues/50643
156-
it('with name', () => {
157-
const { container } = render(<Upload name="bamboo" />);
158-
expect(container.querySelector('input')!.name).toBe('bamboo');
159-
});
160-
161155
it('should pass through data & aria attributes', () => {
162156
const { container } = render(
163157
<Upload
@@ -375,6 +369,31 @@ describe('uploader', () => {
375369
await new Promise(resolve => setTimeout(resolve, 100));
376370
await new Promise(resolve => setTimeout(resolve, 2000));
377371
});
372+
373+
it('should pass file to request', done => {
374+
const fakeRequest = jest.fn((file) => {
375+
expect(file).toEqual(expect.objectContaining({
376+
filename: 'file', // <= https://github.com/react-component/upload/pull/574
377+
file: expect.any(File),
378+
method: 'post',
379+
onError: expect.any(Function),
380+
onProgress: expect.any(Function),
381+
onSuccess: expect.any(Function),
382+
data: expect.anything(),
383+
}));
384+
385+
done();
386+
});
387+
388+
const { container } = render(<Upload customRequest={fakeRequest} />);
389+
const input = container.querySelector('input')!;
390+
const files = [new File([''], 'success.png', { type: 'image/png' })];
391+
Object.defineProperty(files, 'item', {
392+
value: i => files[i],
393+
});
394+
395+
fireEvent.change(input, { target: { files } });
396+
});
378397
});
379398

380399
describe('directory uploader', () => {

0 commit comments

Comments
 (0)