mirror of
https://github.com/django-components/django-components.git
synced 2025-10-17 17:27:13 +00:00
feat: dynamic slots, fills, and provides (#609)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
6793aec9b4
commit
b90961b4a7
8 changed files with 521 additions and 140 deletions
|
@ -188,6 +188,38 @@ class HtmlAttrsTests(BaseTestCase):
|
|||
)
|
||||
self.assertNotIn("override-me", rendered)
|
||||
|
||||
def test_tag_spread(self):
|
||||
@register("test")
|
||||
class AttrsComponent(Component):
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
<div {% html_attrs ...props class="another-class" %}>
|
||||
content
|
||||
</div>
|
||||
""" # noqa: E501
|
||||
|
||||
def get_context_data(self, *args, attrs):
|
||||
return {
|
||||
"props": {
|
||||
"attrs": attrs,
|
||||
"defaults": {"class": "override-me"},
|
||||
"class": "added_class",
|
||||
"data-id": 123,
|
||||
},
|
||||
}
|
||||
|
||||
template = Template(self.template_str)
|
||||
rendered = template.render(Context({"class_var": "padding-top-8"}))
|
||||
self.assertHTMLEqual(
|
||||
rendered,
|
||||
"""
|
||||
<div @click.stop="dispatch('click_event')" class="added_class another-class padding-top-8" data-id="123" x-data="{hello: 'world'}">
|
||||
content
|
||||
</div>
|
||||
""", # noqa: E501
|
||||
)
|
||||
self.assertNotIn("override-me", rendered)
|
||||
|
||||
def test_tag_aggregate_args(self):
|
||||
@register("test")
|
||||
class AttrsComponent(Component):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue