Permalink
Browse files

Fix linkProps in upload fileList

1. should support json string format
2. should be able to override props like rel, target, title and etc
  • Loading branch information...
afc163 committed Sep 14, 2018
1 parent 9d5920b commit efb23c1525858114460bfe3bd5fcb18c9f236bdc
Showing with 44 additions and 3 deletions.
  1. +5 −3 components/upload/UploadList.tsx
  2. +39 −0 components/upload/__tests__/upload.test.js
@@ -136,15 +136,17 @@ export default class UploadList extends React.Component<UploadListProps, any> {
[`${prefixCls}-list-item`]: true,
[`${prefixCls}-list-item-${file.status}`]: true,
});
const linkProps = typeof file.linkProps === 'string'
? JSON.parse(file.linkProps) : file.linkProps;
const preview = file.url ? (
<a
{...file.linkProps}
href={file.url}
target="_blank"
rel="noopener noreferrer"
className={`${prefixCls}-list-item-name`}
onClick={e => this.handlePreview(file, e)}
title={file.name}
{...linkProps}
href={file.url}
onClick={e => this.handlePreview(file, e)}
>
{file.name}
</a>
@@ -185,4 +185,43 @@ describe('Upload', () => {
});
});
});
it('should support linkProps as object', () => {
const fileList = [{
uid: '-1',
name: 'foo.png',
status: 'done',
url: 'http://www.baidu.com/xxx.png',
linkProps: {
download: 'image',
rel: 'noopener',
},
}];
const wrapper = mount(
<Upload fileList={fileList} />
);
const linkNode = wrapper.find('a.ant-upload-list-item-name');
expect(linkNode.props().download).toBe('image');
expect(linkNode.props().rel).toBe('noopener');
});
it('should support linkProps as json stringify', () => {
const linkPropsString = JSON.stringify({
download: 'image',
rel: 'noopener',
});
const fileList = [{
uid: '-1',
name: 'foo.png',
status: 'done',
url: 'http://www.baidu.com/xxx.png',
linkProps: linkPropsString,
}];
const wrapper = mount(
<Upload fileList={fileList} />
);
const linkNode = wrapper.find('a.ant-upload-list-item-name');
expect(linkNode.props().download).toBe('image');
expect(linkNode.props().rel).toBe('noopener');
});
});

0 comments on commit efb23c1

Please sign in to comment.