mirror of
https://github.com/pyscript/pyscript.git
synced 2026-02-26 08:03:59 -05:00
Temporary fix to update_all (Immediate bug fix) (#2455)
* update elementCollection.update_all * update_all new test cases * restore pyscript.js * restore package-lock.json * Finalize comment
This commit is contained in:
@@ -1159,18 +1159,19 @@ class ElementCollection:
|
||||
elements.extend(_find_and_wrap(element._dom_element, selector))
|
||||
return ElementCollection(elements)
|
||||
|
||||
def update_all(self, **kwargs):
|
||||
def update_all(self, classes=None, style=None, **kwargs):
|
||||
"""
|
||||
Explicitly update all elements with the given attributes.
|
||||
Explicitly update all elements with the given `classes`, `style`, and
|
||||
`attributes`. Delegates to each element's `update` method.
|
||||
|
||||
```python
|
||||
collection.update_all(innerHTML="Hello")
|
||||
collection.update_all(classes="active", style={"color": "red"})
|
||||
collection.update_all(className="active", title="Updated")
|
||||
```
|
||||
"""
|
||||
for element in self._elements:
|
||||
for name, value in kwargs.items():
|
||||
setattr(element, name, value)
|
||||
element.update(classes=classes, style=style, **kwargs)
|
||||
|
||||
|
||||
# Special elements with custom methods and mixins.
|
||||
|
||||
@@ -628,6 +628,48 @@ class TestCollection:
|
||||
assert div2.innerHTML == "Hello"
|
||||
assert div2.title == "Test"
|
||||
|
||||
def test_update_all_classes_parameter(self):
|
||||
"""Test updating the class list of all elements."""
|
||||
div1 = web.div()
|
||||
div2 = web.div()
|
||||
collection = web.ElementCollection([div1, div2])
|
||||
|
||||
collection.update_all(classes="active")
|
||||
|
||||
assert "active" in div1.className
|
||||
assert "active" in div2.className
|
||||
|
||||
def test_update_all_style_parameter(self):
|
||||
"""Test updating the style of all elements."""
|
||||
div1 = web.div()
|
||||
div2 = web.div()
|
||||
collection = web.ElementCollection([div1, div2])
|
||||
|
||||
collection.update_all(style={"color": "red"})
|
||||
|
||||
assert div1.style["color"] == "red"
|
||||
assert div2.style["color"] == "red"
|
||||
|
||||
def test_update_all_combined(self):
|
||||
"""Test updating classes, styles, and content together."""
|
||||
div1 = web.div()
|
||||
div2 = web.div()
|
||||
collection = web.ElementCollection([div1, div2])
|
||||
|
||||
collection.update_all(
|
||||
classes="active",
|
||||
style={"color": "blue"},
|
||||
innerHTML="Hi"
|
||||
)
|
||||
|
||||
assert "active" in div1.className
|
||||
assert div1.innerHTML == "Hi"
|
||||
assert div1.style["color"] == "blue"
|
||||
|
||||
assert "active" in div2.className
|
||||
assert div2.innerHTML == "Hi"
|
||||
assert div2.style["color"] == "blue"
|
||||
|
||||
def test_collection_getitem_by_id(self):
|
||||
"""Test looking up element by id in collection."""
|
||||
div1 = web.div(web.p("Child", id="find-me"))
|
||||
|
||||
Reference in New Issue
Block a user