Skip to content

Commit

Permalink
Potential fix for react-csv#350: asyncOnClick = true together with on…
Browse files Browse the repository at this point in the history
…Click just doesnt work
  • Loading branch information
lwoydziak committed Dec 1, 2022
1 parent d1153c1 commit 01957b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-csv",
"version": "2.2.2",
"version": "2.2.3",
"description": "Build CSV files on the fly basing on Array/literal object of data ",
"main": "index.js",
"jsnext:main": "src/index.js",
Expand Down
9 changes: 8 additions & 1 deletion src/components/Link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CSVLink extends React.Component {
constructor(props) {
super(props);
this.buildURI = this.buildURI.bind(this);
this.href = null;
}

buildURI() {
Expand Down Expand Up @@ -50,11 +51,16 @@ class CSVLink extends React.Component {
}

handleAsyncClick(event) {
event.preventDefault();
const done = proceed => {
if (proceed === false) {
event.preventDefault();
return;
}
let link=document.createElement('a');
link.href = this.href;
const {filename} = this.props;
link.download = filename;
link.click();
this.handleLegacy(event, true);
};

Expand Down Expand Up @@ -97,6 +103,7 @@ class CSVLink extends React.Component {

const isNodeEnvironment = typeof window === 'undefined';
const href = isNodeEnvironment ? '' : this.buildURI(data, uFEFF, headers, separator, enclosingCharacter)
this.href = href

return (
<a
Expand Down

0 comments on commit 01957b5

Please sign in to comment.