From e97696710a07cc47e200dc89f4bf6a3c65485cd4 Mon Sep 17 00:00:00 2001 From: William Goldman <60369048+iliketocode2@users.noreply.github.com> Date: Wed, 25 Feb 2026 14:09:17 -0500 Subject: [PATCH] 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 --- core/src/stdlib/pyscript/web.py | 9 ++++--- core/tests/python/tests/test_web.py | 42 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/core/src/stdlib/pyscript/web.py b/core/src/stdlib/pyscript/web.py index 7b2f98c3..d0bacd69 100644 --- a/core/src/stdlib/pyscript/web.py +++ b/core/src/stdlib/pyscript/web.py @@ -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. diff --git a/core/tests/python/tests/test_web.py b/core/tests/python/tests/test_web.py index 84ce6a9a..50773bf8 100644 --- a/core/tests/python/tests/test_web.py +++ b/core/tests/python/tests/test_web.py @@ -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"))