Ignore special_attributes logic for defined props

This commit is contained in:
Masen Furer 2024-10-10 09:38:19 -07:00
parent 1d881be98a
commit 593a0229fa
No known key found for this signature in database
GPG Key ID: B0008AD22B3B3A95
2 changed files with 24 additions and 2 deletions

View File

@ -477,7 +477,9 @@ class Component(BaseComponent, ABC):
# Place data_ and aria_ attributes into custom_attrs # Place data_ and aria_ attributes into custom_attrs
special_attributes = tuple( special_attributes = tuple(
key for key in kwargs if SpecialAttributes.is_special(key) key
for key in kwargs
if key not in fields and SpecialAttributes.is_special(key)
) )
if special_attributes: if special_attributes:
custom_attrs = kwargs.setdefault("custom_attrs", {}) custom_attrs = kwargs.setdefault("custom_attrs", {})

View File

@ -2217,6 +2217,13 @@ def test_has_state_event_triggers(component, output):
assert component._has_stateful_event_triggers() == output assert component._has_stateful_event_triggers() == output
class SpecialComponent(Box):
"""A special component with custom attributes."""
data_prop: Var[str]
aria_prop: Var[str]
@pytest.mark.parametrize( @pytest.mark.parametrize(
("component_kwargs", "exp_custom_attrs", "exp_style"), ("component_kwargs", "exp_custom_attrs", "exp_style"),
[ [
@ -2235,6 +2242,16 @@ def test_has_state_event_triggers(component, output):
{"data-existing": "test", "data-new": "test"}, {"data-existing": "test", "data-new": "test"},
{}, {},
), ),
(
{"data_test": "test", "data_prop": "prop"},
{"data-test": "test"},
{},
),
(
{"aria_test": "test", "aria_prop": "prop"},
{"aria-test": "test"},
{},
),
], ],
) )
def test_special_props(component_kwargs, exp_custom_attrs, exp_style): def test_special_props(component_kwargs, exp_custom_attrs, exp_style):
@ -2245,6 +2262,9 @@ def test_special_props(component_kwargs, exp_custom_attrs, exp_style):
exp_custom_attrs: The expected custom attributes. exp_custom_attrs: The expected custom attributes.
exp_style: The expected style. exp_style: The expected style.
""" """
component = rx.box(**component_kwargs) component = SpecialComponent.create(**component_kwargs)
assert component.custom_attrs == exp_custom_attrs assert component.custom_attrs == exp_custom_attrs
assert component.style == exp_style assert component.style == exp_style
for prop in SpecialComponent.get_props():
if prop in component_kwargs:
assert getattr(component, prop)._var_value == component_kwargs[prop]