Skip to content

Commit

Permalink
add fragment to foreach (reflex-dev#3877)
Browse files Browse the repository at this point in the history
  • Loading branch information
adhami3310 authored Sep 9, 2024
1 parent b7c7197 commit c70cba1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions integration/test_var_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,16 @@ def index():
int_var2=VarOperationState.int_var2,
id="memo_comp_nested",
),
# foreach in a match
rx.box(
rx.match(
VarOperationState.list3.length(),
(0, rx.text("No choices")),
(1, rx.text("One choice")),
rx.foreach(VarOperationState.list3, lambda choice: rx.text(choice)),
),
id="foreach_in_match",
),
)


Expand Down Expand Up @@ -790,6 +800,8 @@ def test_var_operations(driver, var_operations: AppHarness):
# rx.memo component with state
("memo_comp", "1210"),
("memo_comp_nested", "345"),
# foreach in a match
("foreach_in_match", "first\nsecond\nthird"),
]

for tag, expected in tests:
Expand Down
4 changes: 2 additions & 2 deletions reflex/.templates/jinja/web/pages/utils.js.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@
{# Args: #}
{# component: component dictionary #}
{% macro render_iterable_tag(component) %}
{ {%- if component.iterable_type == 'dict' -%}Object.entries({{- component.iterable_state }}){%- else -%}{{- component.iterable_state }}{%- endif -%}.map(({{ component.arg_name }}, {{ component.arg_index }}) => (
<>{ {%- if component.iterable_type == 'dict' -%}Object.entries({{- component.iterable_state }}){%- else -%}{{- component.iterable_state }}{%- endif -%}.map(({{ component.arg_name }}, {{ component.arg_index }}) => (
{% for child in component.children %}
{{ render(child) }}
{% endfor %}
))}
))}</>
{%- endmacro %}


Expand Down

0 comments on commit c70cba1

Please sign in to comment.