mirror of
https://github.com/django-components/django-components.git
synced 2025-10-17 09:17:10 +00:00
feat: Support for HTML attributes and html_attrs
tag (#491)
This commit is contained in:
parent
ba86cee578
commit
610475353f
7 changed files with 1156 additions and 32 deletions
|
@ -986,3 +986,36 @@ class SlotBehaviorTests(BaseTestCase):
|
|||
</custom-template>
|
||||
""",
|
||||
)
|
||||
|
||||
|
||||
class AggregateInputTests(BaseTestCase):
|
||||
def test_agg_input_accessible_in_get_context_data(self):
|
||||
@component.register("test")
|
||||
class AttrsComponent(component.Component):
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
<div>
|
||||
attrs: {{ attrs|safe }}
|
||||
my_dict: {{ my_dict|safe }}
|
||||
</div>
|
||||
"""
|
||||
|
||||
def get_context_data(self, *args, attrs, my_dict):
|
||||
return {"attrs": attrs, "my_dict": my_dict}
|
||||
|
||||
template_str: types.django_html = """
|
||||
{% load component_tags %}
|
||||
{% component "test" attrs:@click.stop="dispatch('click_event')" attrs:x-data="{hello: 'world'}" attrs:class=class_var my_dict:one=2 %}
|
||||
{% endcomponent %}
|
||||
""" # noqa: E501
|
||||
template = Template(template_str)
|
||||
rendered = template.render(Context({"class_var": "padding-top-8"}))
|
||||
self.assertHTMLEqual(
|
||||
rendered,
|
||||
"""
|
||||
<div>
|
||||
attrs: {'@click.stop': "dispatch('click_event')", 'x-data': "{hello: 'world'}", 'class': 'padding-top-8'}
|
||||
my_dict: {'one': 2}
|
||||
</div>
|
||||
""", # noqa: E501
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue