Accordion item icon #43123
|
In Bootstrap 5, the chevron icon was added via a Bootstrap 6 seems to have dropped this, which forces everyone to include the icon. I get that this allows much greater, easier icon customization, but we could also use a CSS variable to store the SVG and override it with a custom style rule if we wanted. Were there other reasons for this decision, and is there a way to revert to automatically including it? Even if we took a "hybrid" approach and included an |
Replies: 1 comment
|
On the "why": the change came with #41953, which rebuilt the accordion on native You can get one back today, though, without touching the markup. In .accordion {
--accordion-auto-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}
.accordion-header:not(:has(.accordion-icon))::after {
flex-shrink: 0;
inline-size: var(--bs-accordion-btn-icon-width);
block-size: var(--bs-accordion-btn-icon-width);
margin-inline-start: auto;
content: "";
background-color: currentcolor;
mask: var(--accordion-auto-icon) center / contain no-repeat;
transition: var(--bs-accordion-btn-icon-transition);
}
.accordion-item[open] > .accordion-header:not(:has(.accordion-icon))::after {
transform: var(--bs-accordion-btn-icon-transform);
}
@media (prefers-reduced-motion: reduce) {
.accordion-header:not(:has(.accordion-icon))::after {
transition: none;
}
}
I tested it against the published |
On the "why": the change came with #41953, which rebuilt the accordion on native
<details>/<summary>with thenameattribute. The PR description doesn't give a specific reason for moving the chevron into markup, so only the maintainers can answer that. Since v6 is still in alpha, this thread is the right place to push for an automatic icon.You can get one back today, though, without touching the markup. In
6.0.0-alpha.1, the chevron's size, rotation and transition are all driven by accordion CSS variables. A::afteron.accordion-headercan use the same variables, with the SVG stored in a custom property as you suggested: