Skip to content

Commit c70cba1

Browse files
authored
add fragment to foreach (#3877)
1 parent b7c7197 commit c70cba1

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

integration/test_var_operations.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,16 @@ def index():
593593
int_var2=VarOperationState.int_var2,
594594
id="memo_comp_nested",
595595
),
596+
# foreach in a match
597+
rx.box(
598+
rx.match(
599+
VarOperationState.list3.length(),
600+
(0, rx.text("No choices")),
601+
(1, rx.text("One choice")),
602+
rx.foreach(VarOperationState.list3, lambda choice: rx.text(choice)),
603+
),
604+
id="foreach_in_match",
605+
),
596606
)
597607

598608

@@ -790,6 +800,8 @@ def test_var_operations(driver, var_operations: AppHarness):
790800
# rx.memo component with state
791801
("memo_comp", "1210"),
792802
("memo_comp_nested", "345"),
803+
# foreach in a match
804+
("foreach_in_match", "first\nsecond\nthird"),
793805
]
794806

795807
for tag, expected in tests:

reflex/.templates/jinja/web/pages/utils.js.jinja2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@
6464
{# Args: #}
6565
{# component: component dictionary #}
6666
{% macro render_iterable_tag(component) %}
67-
{ {%- if component.iterable_type == 'dict' -%}Object.entries({{- component.iterable_state }}){%- else -%}{{- component.iterable_state }}{%- endif -%}.map(({{ component.arg_name }}, {{ component.arg_index }}) => (
67+
<>{ {%- if component.iterable_type == 'dict' -%}Object.entries({{- component.iterable_state }}){%- else -%}{{- component.iterable_state }}{%- endif -%}.map(({{ component.arg_name }}, {{ component.arg_index }}) => (
6868
{% for child in component.children %}
6969
{{ render(child) }}
7070
{% endfor %}
71-
))}
71+
))}</>
7272
{%- endmacro %}
7373

7474

0 commit comments

Comments
 (0)