classList.js icon indicating copy to clipboard operation
classList.js copied to clipboard

No normalization of add/remove/toggle in IE10 and IE11

Open PatrickEickmeier opened this issue 9 years ago • 17 comments

I tested the polyfill in IE10 and IE11 (Win7 on a virtual machine) and the functions still have partial support of classList. Multiple parameters in the add() and remove() functions still don't work.

    if (!("classList" in document.createElement("_"))
        || document.createElementNS && !("classList" in document.createElementNS("http://www.w3.org/2000/svg", "g"))) {

The last condition !("classList" in document.createElementNS("http://www.w3.org/2000/svg", "g")) evaluates to true, so the part for no classlist support will be executed. The part for partial classlist supported browsers won't be executed in IE10/11.

I could "fix" the issue by changing || to && in line18/19:

    if (!("classList" in document.createElement("_"))
        && document.createElementNS && !("classList" in document.createElementNS("http://www.w3.org/2000/svg", "g"))) {

It seems to work for IE10/11, but don't know if is could be an issue for other browsers.

PatrickEickmeier avatar Dec 11 '15 14:12 PatrickEickmeier

+1 having the same issue here.

Rendez avatar Dec 17 '15 08:12 Rendez

This regression was introduced by https://github.com/eligrey/classList.js/commit/6379aea0dc04843b4c1505dfa4e80c06fdc93f45 in #40.

dgraham avatar Feb 13 '16 01:02 dgraham

+1 on this. Having the same issue.

Tokimon avatar May 10 '16 09:05 Tokimon

@eligrey hello?

stevenvachon avatar May 11 '16 13:05 stevenvachon

The suggested fix here breaks SVG support in IE11.

tremby avatar Jun 30 '16 02:06 tremby

@tbranyen would you mind publishing and older version of this package on npm? Right now the only release on npm contains this bug. You could check out the 2014-12-13 tag and publish it as 1.1.20141213, which won't break semver. Here's an example in a stackoverflow answer you can follow to publish an older version.

vestride avatar Jul 26 '16 08:07 vestride

What about simplification? We may just use:

if (!("classList" in document.createElement("_"))) {

So the normalization would also work as expected.

drgullin avatar Jul 28 '16 11:07 drgullin

Does that detect also whether support exists for SVG elements?

tremby avatar Jul 28 '16 11:07 tremby

@eligrey are you deceased?

stevenvachon avatar Aug 11 '16 14:08 stevenvachon

@PatAtMacadamian comments?

stevenvachon avatar Aug 11 '16 14:08 stevenvachon

For anyone needing this, I have a pull request in, but since that will probably never get merged, you can point to my branch in your projects: https://github.com/stevenvachon/classList.js

stevenvachon avatar Aug 13 '16 22:08 stevenvachon

@stevenvachon make it available at npm, please.

drgullin avatar Sep 09 '16 05:09 drgullin

@fronteed it already is:

"dependencies": {
  "classlist.js": "stevenvachon/classList.js"
}

stevenvachon avatar Sep 09 '16 15:09 stevenvachon

apart from failing to normalize the api, the current toggle/force polyfill also doesn’t really conform to what everyone else is doing. while I’m not 100% sure that the spec defines this exact edge case (it comes down to the definition of what a passed value is and truthy-/falsyness), every browser seems to consider undefined as not passed, while the current implementation considers undefined false and therefor breaks compatibility.

kmohrf avatar Oct 07 '16 18:10 kmohrf

In my opinion undefined should definitely be considered "not passed". null should probably be considered false, though I'm not so sure about that.

Probably best to do what the majority of native browser implementations do, if the spec isn't clear enough.

tremby avatar Oct 07 '16 19:10 tremby

null is considered false in other implementations. I suppose the usual thruthy/falsy conversion applies except for undefined. The spec explicitly mentions true and false and in the chromium codebase toggle accepts a bool in the DOMTokenList interface. So I guess they have a standard behaviour concerning function call value transformations for these kind of APIs and undefined is simply dropped while other values are converted to bool.

kmohrf avatar Oct 07 '16 20:10 kmohrf

This should be fixed: https://github.com/eligrey/classList.js/pull/57

Published via: https://github.com/yola/classlist-polyfill

beck avatar May 02 '17 21:05 beck