svgdotjs / svg.js

The lightweight library for manipulating and animating SVG
https://svgjs.dev
Other
11.04k stars 1.08k forks source link

Return value from Container.svg() (actually Dom.svg()) is not useful #1130

Closed pragdave closed 4 years ago

pragdave commented 4 years ago

Bug report

It looks like Dom.svg() is returning the parent element, and not the newly created internal svg element.

Fiddle

Here's a pen: https://codepen.io/pragdave/pen/qBbREKO

Explanation

I can't use nested() because:

  1. I need the embedded SVG's attributes to be directly exposed, and

  2. nested returns a DOM element, not a container.

I'm guessing this behavior is because svg() can accept multiple SVG elements, and so the choice of return value is ambiguous. Perhaps it could just return the first?

Cheers

Dave

pragdave commented 4 years ago

Or.. is the canonical way to do

let el = SVG.SVG(some svg)
draw.add(el)
Fuzzyma commented 4 years ago

I'm guessing this behavior is because svg() can accept multiple SVG elements, and so the choice of return value is ambiguous

Correct!

Perhaps it could just return the first?

Thats a good idea but would introduce a breaking change

Or.. is the canonical way to do

This will create an element based on the first element of the given string. So jeah - if it is only one element this way is the prefered one

pragdave commented 4 years ago

Thanks