Skip to content

Commit

Permalink
Update index.tsx
Browse files Browse the repository at this point in the history
mylank solution for multiple clicks
vivien000#7
  • Loading branch information
hadariru authored Apr 3, 2024
1 parent 3d4dad2 commit cb46b13
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions st_click_detector/frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,22 @@ function onRender(event: Event): void {
div.style.fontFamily = data.theme.font
}
div.innerHTML = transparentPixel + data.args["html_content"] + transparentPixel

// Add click detection for each hyperlink
let links = document.getElementsByTagName("a");
for (let i = 0; i < links.length; i++) {
if (links[i].id !== "") {
links[i].onclick = function (): void {
Streamlit.setComponentValue(links[i].id)
if (curr_val == links[i].id) {
curr_val = links[i].id + '#'
} else {
curr_val = links[i].id
}
Streamlit.setComponentValue(curr_val)
}
}
}
}

Streamlit.events.addEventListener(Streamlit.RENDER_EVENT, onRender)
Streamlit.setComponentReady()
Streamlit.setComponentReady()

0 comments on commit cb46b13

Please sign in to comment.