From cb46b1323436257875850fd56eee6dceaa23fa77 Mon Sep 17 00:00:00 2001 From: hadariru <155623884+hadariru@users.noreply.github.com> Date: Wed, 3 Apr 2024 18:00:17 +0900 Subject: [PATCH] Update index.tsx mylank solution for multiple clicks https://github.com/vivien000/st-click-detector/issues/7 --- st_click_detector/frontend/src/index.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/st_click_detector/frontend/src/index.tsx b/st_click_detector/frontend/src/index.tsx index a6aa8cc..bd3ae18 100644 --- a/st_click_detector/frontend/src/index.tsx +++ b/st_click_detector/frontend/src/index.tsx @@ -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() \ No newline at end of file +Streamlit.setComponentReady()