Skip to content
This repository has been archived by the owner on Nov 11, 2019. It is now read-only.

DOMTokenList.add/remove normalize dupes/whitespace even if they're no-ops, but .toggle doesn't #118

Closed
ayg opened this issue Apr 5, 2017 · 3 comments
Assignees

Comments

@ayg
Copy link

ayg commented Apr 5, 2017

Per the current spec, this outputs "a b c c d d":

data:text/html,<!doctype html>
<script>
var res = "";
var span = document.createElement("span");
span.setAttribute("class", "a a");
span.classList.add("a");
res += span.getAttribute("class");
span.setAttribute("class", "b b");
span.classList.remove("a");
res += " " + span.getAttribute("class");
span.setAttribute("class", "c c");
span.classList.toggle("c", true);
res += " " + span.getAttribute("class");
span.setAttribute("class", "d d");
span.classList.toggle("a", false);
res += " " + span.getAttribute("class");
document.documentElement.textContent = res;
</script>

This is not consistent. If we want add/remove to normalize even if they're no-ops, so should toggle. This is especially true because force-toggle is otherwise precisely identical AFAICT, and the slight difference is confusing.

replace also doesn't normalize if the token doesn't exist, but that doesn't bother me as much since it doesn't otherwise behave identically to add/remove.

@ayg
Copy link
Author

ayg commented Apr 18, 2017

@annevk? I hit this because it complicates testing -- if force-toggle worked the same as add/remove, we could reuse add/remove tests for force-toggle for free.

@annevk
Copy link
Member

annevk commented Apr 18, 2017

Wrong repository again? Happy to make this change if you could copy the issue over, especially as you have tests.

@yongsheng
Copy link
Collaborator

yongsheng commented May 9, 2017

seems it's a bug. will test it in different UAs.

yongsheng pushed a commit to yongsheng/dom that referenced this issue May 17, 2017
1. Define token set using ordered set for DOMTokenList.

2. Refine DOMTokenList's length and indexing.

3. Make DOMTokenList's contains() not throw because it doesn't modify token set.

4. Combine DOMSettableTokenList into DOMTokenList, because DOMTokenList.value

   could be a stringifier attribute, therefore it is OK to make 'value' a

   stringifier.

5. Use less loops for DOMTokenList's add() and remove().

6. Always update a DOMTokenList when invoking toggle(). This shall normalize

   duplicates and whitespaces even if they're no-ops like add()/remove().

   This fixes w3c#118 too.

7. Introduce DOMTokenList's replace(). This shall fix w3c#117 together.

8. Introduce DOMTokenList's supports().
yongsheng pushed a commit that referenced this issue May 17, 2017
1. Define token set using ordered set for DOMTokenList.

2. Refine DOMTokenList's length and indexing.

3. Make DOMTokenList's contains() not throw because it doesn't modify token set.

4. Combine DOMSettableTokenList into DOMTokenList, because DOMTokenList.value

   could be a stringifier attribute, therefore it is OK to make 'value' a

   stringifier.

5. Use less loops for DOMTokenList's add() and remove().

6. Always update a DOMTokenList when invoking toggle(). This shall normalize

   duplicates and whitespaces even if they're no-ops like add()/remove().

   This fixes #118 too.

7. Introduce DOMTokenList's replace(). This shall fix #117 together.

8. Introduce DOMTokenList's supports().
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants