Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique id #21

Open
mberrg opened this issue Aug 19, 2020 · 3 comments
Open

Unique id #21

mberrg opened this issue Aug 19, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@mberrg
Copy link

mberrg commented Aug 19, 2020

I'm missing an option to prefix id inside the svg with a random string. Conflicting id with multiple SVGs can be a problem, similar tools for react does this.

@shrpne
Copy link
Owner

shrpne commented Aug 20, 2020

Interesting, I have to investigate this. If you have some examples, I will glad to take a look at them.

As a workaround, you can use <vue-inline-svg :id="false"/> to remove root ids and transformSource to update source ids.

@ptsneves
Copy link

ptsneves commented Dec 22, 2020

@shrpne it is quite simple.
Each element in svg can have an id, and as a standalone svg it is up to the svg provider to guarantee it is unique in the document.

The problem happens when we use vue-inline-svg to inject and expand the same svg multiple times in the same html multiple times. Then the svg's internal element ids will belong to the whole page document, and if the svg is expanded several times, there will be collisions. Non unique ids are not allowed as per standards.

Edit:
I will try my hand on transforming the source svg into having classes with the name of the ids. This way there can be a single css styling applied to all the instances of the svg's inner element in the HTML document
@shrpne would you accept a prop where the enables transformation of ids into classes?

@shrpne
Copy link
Owner

shrpne commented Apr 27, 2023

Here is example of transforming function

https://github.com/gilbarbara/react-inlinesvg/blob/main/src/index.tsx#L296

@shrpne shrpne added the enhancement New feature or request label Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants