fmmattioni / downloadthis

Implement Download Buttons in rmarkdown 💾
https://fmmattioni.github.io/downloadthis/
Other
147 stars 5 forks source link

Window jumps to top of page when clicking download button #30

Closed daranzolin closed 1 year ago

daranzolin commented 1 year ago

I have a long Quarto report with several downloadthis buttons. The buttons work great, but the window jumps to the top of the page after clicking, annoying some of my users. Is there someway to adjust the href argument here to prevent this behavior?

https://github.com/fmmattioni/downloadthis/blob/0718d0c0ae74868eb8ba42c72c18817d59cd1914/R/download.R#L268-L270

fmmattioni commented 1 year ago

Hi @daranzolin, could you provide me a quick reprex that I can reproduce this behavior?

daranzolin commented 1 year ago

Sure, see the source code below. I've observed this behavior in both Firefox and Chrome. Clicking the download button jumps to the top of the page.

---
title: "downloadthis reprex"
format: html
editor: visual
---

<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

```{r}
library(downloadthis)

mtcars %>%
  download_this(
    output_name = "mtcars data set",
    output_extension = ".csv",
    button_label = "Download data",
    button_type = "warning",
    has_icon = TRUE,
    icon = "fa fa-save"
  )
daranzolin commented 1 year ago

Update: this Stackoverflow solution works for single pages, but not when the output includes tabs.

Edit: this solution does work for me, I just had to loop through each button and update the href in button.html.

vincentmq commented 1 year ago

+1 to this. Is there an update to this issue?