Skip to content

Commit

Permalink
feat: add onClick event to PDFDownloadLink (#1902)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamduncan authored Jul 2, 2022
1 parent 0fcc594 commit d011983
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/silly-rice-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@react-pdf/renderer': minor
---

feat: add onClick event to PDFDownloadLink
1 change: 1 addition & 0 deletions packages/renderer/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ declare namespace ReactPDF {
children?:
| React.ReactNode
| ((params: BlobProviderParams) => React.ReactNode);
onClick?: function;

This comment has been minimized.

Copy link
@iansummerlin

iansummerlin Jul 4, 2022

Function *

This comment has been minimized.

Copy link
@diegomura

diegomura Jul 4, 2022

Owner

Can you submit a fix @iansummerlin ? 🙏

This comment has been minimized.

Copy link
@adamduncan

adamduncan Jul 6, 2022

Author Contributor

Apologies folks, that was my fault — silly typo. Fix PR: #1924

}

/**
Expand Down
8 changes: 7 additions & 1 deletion packages/renderer/src/dom/PDFDownloadLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const PDFDownloadLink = ({
className,
document: doc,
fileName = 'document.pdf',
onClick,
}) => {
const [instance, updateInstance] = usePDF({ document: doc });

Expand All @@ -27,13 +28,18 @@ export const PDFDownloadLink = ({
}
};

const handleClick = event => {
handleDownloadIE();
if (typeof onClick === 'function') onClick(event, instance);
};

return (
<a
style={style}
href={instance.url}
download={fileName}
className={className}
onClick={handleDownloadIE}
onClick={handleClick}
>
{typeof children === 'function' ? children(instance) : children}
</a>
Expand Down

0 comments on commit d011983

Please sign in to comment.