Skip to content

Commit

Permalink
Download button in DocItem to download rather than opening in new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavberi committed Dec 20, 2024
1 parent 1acb0d9 commit a2795a7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/components/docs/DocItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ export default function DocItem({

const handleDownload = () => {
const fileUrl = getFile(buildFileName(file, version), true, true);
window.open(fileUrl, "_blank");

// Create an anchor element
const anchor = document.createElement("a");
anchor.href = fileUrl;
anchor.download = buildFileName(file, version);

// Append it to the body (necessary for some browsers)
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
};

const handleVersionChange = (event) => {
versionChange(event.target.value);
};
Expand Down

0 comments on commit a2795a7

Please sign in to comment.