Repository: 12rambau/sepal_ui

Issue:
make get_children recursively again
previous implementation used recursion to find all children within the widget that matches with the query, now it returns only first level of matching children, could we make it reclusively again?

Discussion:

Patch:
diff --git a/sepal_ui/sepalwidgets/sepalwidget.py b/sepal_ui/sepalwidgets/sepalwidget.py
index 40826809..00cbe015 100644
--- a/sepal_ui/sepalwidgets/sepalwidget.py
+++ b/sepal_ui/sepalwidgets/sepalwidget.py
@@ -177,11 +177,11 @@ class SepalWidget(v.VuetifyWidget):
             is_klass = isinstance(w, klass)
             is_val = w.attributes.get(attr, "niet") == value if attr and value else True
 
-            # asumption: searched element won't be nested inside one another
             if is_klass and is_val:
                 elements.append(w)
-            else:
-                elements = self.get_children(w, klass, attr, value, id_, elements)
+
+            # always search for nested elements
+            elements = self.get_children(w, klass, attr, value, id_, elements)
 
         return elements
 


Test patch:
diff --git a/tests/test_SepalWidget.py b/tests/test_SepalWidget.py
index 3abd719f..22699d69 100644
--- a/tests/test_SepalWidget.py
+++ b/tests/test_SepalWidget.py
@@ -108,24 +108,23 @@ class TestSepalWidget:
         assert len(res) == 0
 
         # search for specific attributes in any class
-        # one alert that could match is ignored because the parent card is identified
-        # earlier, that's a feature
         res = test_card.get_children(attr="id", value=3)
-        assert len(res) == 6
+        assert len(res) == 7
         assert isinstance(res[0], sw.Alert)
         assert isinstance(res[1], sw.Alert)
         assert isinstance(res[2], sw.Alert)
         assert isinstance(res[3], sw.Card)
         assert isinstance(res[4], sw.Alert)
-        assert isinstance(res[5], sw.Btn)
+        assert isinstance(res[5], sw.Alert)
+        assert isinstance(res[6], sw.Btn)
 
-        # missing value (all children will match so nested are ignored)
+        # missing value (all children will match including icons)
         res = test_card.get_children(attr="id")
-        assert len(res) == 10
+        assert len(res) == 40
 
-        # missing attr (all children will match so nested are ignored)
+        # missing attr (all children will match including icons)
         res = test_card.get_children(value=5)
-        assert len(res) == 10
+        assert len(res) == 40
 
         # no match search attr
         res = test_card.get_children(attr="toto", value="toto")