Editing svg #shadow-root content

I have an svg that has #shadow-root content that houses a down arrow with a fill on it. See images. I want to edit this fill to make it transparent, but I do not have access to the html. The only way I can think of is removing the element from the dom and adding in the same element html without the fill. Is there a better way?
No description
No description
48 Replies
b1mind
b1mind7mo ago
the fill is currentColor so you can just change the svg {color:;} o the circle is not though gg
vince
vinceOP7mo ago
Yea sorry should have worded it better 😅
b1mind
b1mind7mo ago
I mean you had it highlighted I just am bad with screen shots
vince
vinceOP7mo ago
I just realized even with JS I can't see the shadow root so I don't even think this is possible lol All I get spitting out the html :( <use xlink:href="#chevron-down"></use>
b1mind
b1mind7mo ago
yea its a sprite with one icon lol
vince
vinceOP7mo ago
I guess I could hardcode the HTML from the DOM in a variable and then just replace it
b1mind
b1mind7mo ago
what is the source? this part of some component you don't have control of?
Rägnar O'ock
Rägnar O'ock7mo ago
That doesn't work with shadow DOM
vince
vinceOP7mo ago
Yea from what I remember, the codebase has their svgs setup so they're reusable so it does this shadow dom thingy but yea I don't have access to the entire codebase. I just make edits via the page builder and add inline css and js to add custom styles haha
b1mind
b1mind7mo ago
why would anyone do this then all sounds stupid af
Rägnar O'ock
Rägnar O'ock7mo ago
Do what?
b1mind
b1mind7mo ago
sprite with one icon... shadowdom no point if you can't use stuff like currentColor
vince
vinceOP7mo ago
I don't remember how it's setup in the codebase but it is really nice how they have it, so you can just do something like <svg #arrow> and it replaces it with the arrow svg paths
b1mind
b1mind7mo ago
custom sprite with custom props and fallbacks ❤️ i.e. fill="var(--svg-fill, currentColor)" https://icones.js.org/ bag em and tag em few edits and wala
Rägnar O'ock
Rägnar O'ock7mo ago
<use> is basically SVG's <img> it allows you to load a file in as content. When that file is svg, it creates a shadow dom fragment to display the svg content. There's no benefit that I know of of using <use> over <img> so I don't know why they chose it. Custom props don't propagate in shadow DOM
b1mind
b1mind7mo ago
listen I do both all the time So don't tell me I can't with <use>
Rägnar O'ock
Rägnar O'ock7mo ago
Shadow DOM is basically a parallel dimensions you can only interact with via JS and some css pseudo classes
ἔρως
ἔρως7mo ago
you can also set the styles to the element itself
b1mind
b1mind7mo ago
this is not factual least not really
Rägnar O'ock
Rägnar O'ock7mo ago
How so?
b1mind
b1mind7mo ago
because its very wrong they are so far from the same thing
Rägnar O'ock
Rägnar O'ock7mo ago
Can you be... More specific maybe ? XD
b1mind
b1mind7mo ago
there is all the benifit of doing <use> over <img src> for one its still a <svg> that way and yes you can use custom props and current color to effect them
Rägnar O'ock
Rägnar O'ock7mo ago
And it's not meant to be fact, I said that I didn't knew any benefit of using one over the other
b1mind
b1mind7mo ago
let me find example..
ἔρως
ἔρως7mo ago
Edit fiddle - JSFiddle - Code Playground
JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.
ἔρως
ἔρως7mo ago
what jochem said works
b1mind
b1mind7mo ago
https://github.com/b1mind/bfolio/blob/dev/src/lib/component/SocialIcons.svelte I do it for my social icons thought I ahd a codepen but cant find it
vince
vinceOP7mo ago
HOW MANY SPACES DO YOU USE FOR TABS ?!
Rägnar O'ock
Rägnar O'ock7mo ago
Because the element is from the same file, it doesn't get the --x from the svg use, but directly via the symbol.
b1mind
b1mind7mo ago
thats your default not mine I use 1 tab (2spaces) for everything
ἔρως
ἔρως7mo ago
i can't test a different file
vince
vinceOP7mo ago
No description
b1mind
b1mind7mo ago
Oh yea this
Rägnar O'ock
Rägnar O'ock7mo ago
Check your GH account settings, you can customize it there, it defaults to HTML's 8 space
b1mind
b1mind7mo ago
No description
b1mind
b1mind7mo ago
also people that use .svg in a <img src=""> are crazy that part you are not wrong no point 🤣 ok mine don't show as shadow dom though :think: also I never remember them ever doing that so thats web component shit no?
vince
vinceOP7mo ago
Idk but here's my amazing solution
const arrowSvg = `
<g fill="none" fill-rule="evenodd">
<circle cx="12" cy="12" r="12"></circle>
<path d="M5.293 10.623a.918.918 0 0 1 0-1.345c.36-.342.928-.369 1.32-.079l.094.08L12 14.31l5.293-5.032c.36-.342.928-.369 1.32-.079l.094.08c.36.342.388.882.083 1.254l-.083.09L12 17l-6.707-6.377z" fill="currentColor" fill-rule="nonzero"></path>
</g>
`;

const arrows = accordion?.querySelectorAll('svg.chevron');
arrows && arrows.forEach((arrow) => arrow.innerHTML = arrowSvg);
const arrowSvg = `
<g fill="none" fill-rule="evenodd">
<circle cx="12" cy="12" r="12"></circle>
<path d="M5.293 10.623a.918.918 0 0 1 0-1.345c.36-.342.928-.369 1.32-.079l.094.08L12 14.31l5.293-5.032c.36-.342.928-.369 1.32-.079l.094.08c.36.342.388.882.083 1.254l-.083.09L12 17l-6.707-6.377z" fill="currentColor" fill-rule="nonzero"></path>
</g>
`;

const arrows = accordion?.querySelectorAll('svg.chevron');
arrows && arrows.forEach((arrow) => arrow.innerHTML = arrowSvg);
b1mind
b1mind7mo ago
ah the repaints but you do what you gotta do
vince
vinceOP7mo ago
you don't understand how many of these we have that are inline
b1mind
b1mind7mo ago
even worse perf then xD
vince
vinceOP7mo ago
We easily have 10k lines of css and js in <style> and <script> tags added by overrides and the js is all dom manipulation on the client
b1mind
b1mind7mo ago
that makes me kinda whooozy why not just have a better DOM solution Sounds like w/e yall using sux ass
vince
vinceOP7mo ago
It's a closed-source cms we're using that (i think) is built off of Spring Boot and they didn't really do any knowledge transfers... and the documentation is really bad. The client stuff isn't too bad but it's not really clear how or where to add overrides since everything is just built as a module... so when you have a whole new page where each module needs something custom... like do we just make another module for it? But then we're really just moving the tech debt around (rather than override, creating a random 'custom' module for it) you know So it's just easiest to add it as an override within the application backend area rather than the codebase Then you could make the argument of 'well the modules should be more flexible' yea you're right but I have no idea how to do any of that within their codebase / with Java 😂
b1mind
b1mind7mo ago
Sounds like a BE dev lead made all the "right" choices "oh look with this we will never have to mess with css/html" then its just a nightmare when you do (which is always)
vince
vinceOP7mo ago
Lol the third party company that owns the cms made the website which is the issue and precisely why the documentation sucks... the documentation is for really basic stuff on their website not the custom stuff they built. so of course if they built it they want to charge extremely high fees to fix it / make custom stuff which is where i come in. instead of paying that company 200-300 an hour they pay me like 1/4 of that
b1mind
b1mind7mo ago
xD

Did you find this page helpful?