Embedding Clickable SVGs in Docusaurus #10921
Replies: 1 comment 2 replies
-
Please share a concrete SVG example so that we can help you. We need the code of the SVG and which things in it should be clickable. The Docusaurus built-in SVG support has recently been extracted as a custom SVGR plugin: https://docusaurus.io/blog/releases/3.7#svgr-plugin It works by converting SVG files automatically to React components. This doesn't allow you to add event listeners to individual SVG shapes. If you want individual shapes to be clickable, you have to convert it to a React component yourself. You can use this conversion tool, for example, https://react-svgr.com/playground/ You can link svg shapes to URLs, or use custom event handlers on them const SvgLinks = () => {
return (
<svg width="200" height="100" viewBox="0 0 200 100">
{/* First shape linking to site 1 */}
<a href="https://example.com" target="_blank" rel="noopener noreferrer">
<path d="M10 10 H 90 V 90 H 10 Z" fill="blue" />
</a>
{/* Second shape linking to site 2 */}
<a href="https://another-example.com" target="_blank" rel="noopener noreferrer">
<path d="M110 10 A40 40 0 1 1 109.99 10" fill="red" />
</a>
</svg>
);
}; (as far as I remember |
Beta Was this translation helpful? Give feedback.
-
Imagine a mind map with multiple branches that redirect to specific website when you click on them
Currently, when I import an SVG either as a React component:
or via Markdown:
![svg file](path/to/svg)
the SVG is rendered as a static image. Although I can select the text within the SVG, any embedded links do not respond or clicks, and the expected behavior (when click on the link on SVG it should redirect me to the specific website ) is not achieved.
For context, I have created diagrams in Excalidraw that include clickable elements and exported them as SVG. These SVGs work correctly on other static site generators, which leads me to believe this issue might be specific to how Docusaurus handles SVG imports.
I would appreciate any insights or recommendations on how to resolve this issue. Specifically, I am interested in approaches that allow the SVG to be rendered inline—ensuring that the anchor tags and interactive elements remain functional in SVG. Some potential workarounds I have considered include:
how to embed svg in docusaurus with clickable links
However i have no any experiance with react but i know markdown
If you have any suggestions or have encountered a similar situation, I would be grateful for your advice.
Beta Was this translation helpful? Give feedback.
All reactions