-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Removing events with element.click(null) throws JS error #878
Comments
Jeah - I guess you are right. That "feature" was lost by converting it to 2.x. However after thinking about it, it might be better to just remove the part of the docs. The "sugar" methods like What do you think? |
Firstly, thanks for the awesome bug report! This is super clear and easy to follow :) I'm afraid that @Fuzzyma is right. This might have been a code change at some point that got lost in the docs somewhere. It depends on how we intend for the users to use these methods. If we are going with event handlers, then Otherwise, I'm all for simplicity, and I do think |
### Fixed - fixed calling `parent()` on `documentFragment`s children (#927) - parser is not focusable anymore (#908) - `SVG.Element.click(null)` correctly unbinds the event (#878) - fix memory leak (#905) ### Added - `SVG.Set` now accepts another Set as input (#893) - `on()/off()` accepts multiple event names as input (backport from 3.0)
Reimplemented. See 2.7.0 |
Bug report
The docs clearly state that to remove an element we can use element.click(null) but doing that throws an JS error:
svg.js:3430 Uncaught TypeError: Cannot read property 'bind' of null at Function.SVG.on (svg.js:3430)
Looking at events.js code, line 33, it's quite clear this is expected:
Calling element.click(null) will result on that listener being null, causing a JS error when we try to do 'listener.bind'
Fiddle
https://jsfiddle.net/c4f8udrb/
Just open developer tools and click mousedown ON and then OFF or just OFF.
Explanation
Now, I'm not sure if this is a documentation error or a bug on SVG.js. Looking at the source code it seems SVG.JS never intended to work that way since there is no code indication of supporting this.
I was looking at the older SVG.js version that I was using (1.1.0-5-gc66d24a) and that had some code for passing null on
SVG.Element.prototype[event] = function(f)
so I'm not sure if that was lost along the way or the docs are wrong and to be honest I don't have a strong opinion if that should be supported or not :)So I'll just wait for the devs opinion on what's the expected result. Either way that should be a nice test case to add to the suite ;)
The text was updated successfully, but these errors were encountered: