|
8 | 8 | from reflex import style |
9 | 9 | from reflex.components.component import evaluate_style_namespaces |
10 | 10 | from reflex.style import Style |
| 11 | +from reflex.utils.exceptions import ReflexError |
11 | 12 | from reflex.vars import VarData |
12 | 13 | from reflex.vars.base import LiteralVar, Var |
13 | 14 |
|
@@ -552,3 +553,31 @@ def test_style_update_with_var_data(): |
552 | 553 | s3 = s1 | s2 |
553 | 554 | assert s3._var_data is not None |
554 | 555 | assert "_varData" not in s3 |
| 556 | + |
| 557 | + |
| 558 | +def test_component_as_css_value_raises_error(): |
| 559 | + """Test that passing a component as a CSS prop value raises ReflexError.""" |
| 560 | + with pytest.raises(ReflexError, match="cannot be used as style values"): |
| 561 | + rx.el.button( |
| 562 | + "Import", |
| 563 | + class_name="px-3 py-2 text-sm font-medium text-gray-600", |
| 564 | + left_icon=rx.icon(tag="cloud_upload", class_name="w-4 h-4"), |
| 565 | + ) |
| 566 | + |
| 567 | + # Test other CSS props that might receive components |
| 568 | + with pytest.raises(ReflexError, match="cannot be used as style values"): |
| 569 | + rx.el.div( |
| 570 | + right_icon=rx.icon(tag="settings"), |
| 571 | + ) |
| 572 | + |
| 573 | + # Test components passed to style dict |
| 574 | + with pytest.raises(ReflexError, match="cannot be used as style values"): |
| 575 | + rx.el.div( |
| 576 | + style={"background": rx.icon(tag="star")}, |
| 577 | + ) |
| 578 | + |
| 579 | + # Test nested style with component |
| 580 | + with pytest.raises(ReflexError, match="cannot be used as style values"): |
| 581 | + rx.el.div( |
| 582 | + style={"_hover": {"content": rx.text("hover")}}, |
| 583 | + ) |
0 commit comments