mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add clear() to Element.classList.
We should support a fast way to remove all classes through the classList instead of having to call removeAttribute() directly. BUG=440529 R=ojan@chromium.org, rafaelw@chromium.org Review URL: https://codereview.chromium.org/788093003
This commit is contained in:
parent
c2916617b4
commit
dfd9a3faa5
@ -83,6 +83,11 @@ void DOMTokenList::setValue(const AtomicString& value)
|
||||
m_element->setAttribute(HTMLNames::classAttr, value);
|
||||
}
|
||||
|
||||
void DOMTokenList::clear()
|
||||
{
|
||||
m_element->removeAttribute(HTMLNames::classAttr);
|
||||
}
|
||||
|
||||
bool DOMTokenList::validateToken(const String& token, ExceptionState& exceptionState)
|
||||
{
|
||||
if (token.isEmpty()) {
|
||||
|
||||
@ -62,6 +62,7 @@ public:
|
||||
void remove(const AtomicString&, ExceptionState&);
|
||||
bool toggle(const AtomicString&, ExceptionState&);
|
||||
bool toggle(const AtomicString&, bool force, ExceptionState&);
|
||||
void clear();
|
||||
|
||||
const AtomicString& toString() const { return value(); }
|
||||
|
||||
|
||||
@ -32,6 +32,8 @@
|
||||
[RaisesException, CustomElementCallbacks] void remove(DOMString... tokens);
|
||||
[RaisesException, CustomElementCallbacks] boolean toggle(DOMString token, optional boolean force);
|
||||
|
||||
void clear();
|
||||
|
||||
[NotEnumerable] stringifier;
|
||||
};
|
||||
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
Running 8 tests
|
||||
Running 9 tests
|
||||
ok 1 Class list should add multiple classes
|
||||
ok 2 Class list should add classes in order
|
||||
ok 3 Class list should remove classes
|
||||
ok 4 Class list should remove multiple classes
|
||||
ok 5 Class list should check for classes
|
||||
ok 6 Class list should get classes by index
|
||||
ok 7 Class list should toggle classes
|
||||
ok 8 Class list should dynamically update style
|
||||
8 tests
|
||||
8 pass
|
||||
ok 5 Class list should clear all classes
|
||||
ok 6 Class list should check for classes
|
||||
ok 7 Class list should get classes by index
|
||||
ok 8 Class list should toggle classes
|
||||
ok 9 Class list should dynamically update style
|
||||
9 tests
|
||||
9 pass
|
||||
0 fail
|
||||
|
||||
@ -48,6 +48,14 @@ describe("Class list", function() {
|
||||
assert.equal(target.classList.toString(), "second");
|
||||
});
|
||||
|
||||
it("should clear all classes", function() {
|
||||
target.classList.add("first");
|
||||
target.classList.add("second");
|
||||
target.classList.clear();
|
||||
assert.equal(target.classList.toString(), "");
|
||||
assert.isFalse(target.hasAttribute("class"));
|
||||
});
|
||||
|
||||
it("should check for classes", function() {
|
||||
target.classList.add("first", "second", "third");
|
||||
assert.isTrue(target.classList.contains("first"));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user