Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing css_class to accordion and accordion-group templates #180

Merged
merged 12 commits into from
Jul 22, 2024
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 2024.3 (TBC)
* Added support for Django 5.1.
* Fixed `accordion.html` and `accordion-group.html` templates to render `css_class` attribute.
* Dropped support for django-crispy-forms 2.2 and earlier.

## 2024.2 (2024-02-24)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="accordion-item">
<div class="accordion-item{% if div.css_class %} {{div.css_class}}{% endif %}">
<h2 class="accordion-header">
<button class="accordion-button{% if not div.active %} collapsed{% endif %}" type="button" data-bs-toggle="collapse" data-bs-target="#{{ div.css_id }}" aria-expanded="true"
aria-controls="{{ div.css_id }}">
Expand Down
2 changes: 1 addition & 1 deletion crispy_bootstrap5/templates/bootstrap5/accordion.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="accordion{% if accordion.flush %} accordion-flush{% endif %}" id="{{ accordion.css_id }}">
<div class="accordion{% if accordion.flush %} accordion-flush{% endif %}{% if accordion.css_class %} {{accordion.css_class}}{% endif %}" id="{{ accordion.css_id }}">
{{ content|safe }}
</div>
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dynamic = [
]
dependencies = [
"django>=4.2",
"django-crispy-forms>=2",
"django-crispy-forms>=2.3",
]
[project.optional-dependencies]
test = [
Expand Down
37 changes: 37 additions & 0 deletions tests/test_layout_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,43 @@ def test_accordion_and_accordiongroup(self):
)
assert parse_form(form) == parse_expected("accordion.html")

def test_accordion_css_class_is_applied(self):
classes = 'one two three'
test_form = SampleForm()
test_form.helper = FormHelper()
test_form.helper.form_tag = False
test_form.helper.layout = Layout(
Accordion(
AccordionGroup("one", "first_name"),
css_class=classes,
css_id='super-accordion'
)
)
html = render_crispy_form(test_form)

assert (
html.count('<div class="accordion %s" id="super-accordion"' % classes)
== 1
)

def test_accordion_group_css_class_is_applied(self):
classes = 'one two three'
test_form = SampleForm()
test_form.helper = FormHelper()
test_form.helper.form_tag = False
test_form.helper.layout = Layout(
Accordion(
AccordionGroup("one", "first_name"),
AccordionGroup("two", "password1", "password2", css_class=classes),
)
)
html = render_crispy_form(test_form)

assert (
html.count('<div class="accordion-item %s"' % classes)
== 1
)

def test_accordion_active_false_not_rendered(self):
test_form = SampleForm()
test_form.helper = FormHelper()
Expand Down
Loading