Problem/Motivation

Bootstrap offers styling options for the thead element: .thead-light and .thead-dark.

However, there's no way to add these via the table.twig component:

{% if header %}
    <thead>
    <tr>
      {% for cell in header %}
      {%
        set cell_classes = [
        cell.active_table_sort ? 'is-active',
      ]
      %}
      <{{ cell.tag }}{{ cell.attributes.addClass(cell_classes) }}>
      {{- cell.content -}}
    </{{ cell.tag }}>
    {% endfor %}
    </tr>
    </thead>
  {% endif %}

It would be nice to have coverage for this Bootstrap feature.

Proposed resolution

Add the option, at least in table.twig.

Example stub

{% if header %}
    <thead{% if thead_style %} class="thead-{{ thead_style }}"{% endif %}>
    <tr>
      {% for cell in header %}
      {%
        set cell_classes = [
        cell.active_table_sort ? 'is-active',
      ]
      %}
      <{{ cell.tag }}{{ cell.attributes.addClass(cell_classes) }}>
      {{- cell.content -}}
    </{{ cell.tag }}>
    {% endfor %}
    </tr>
    </thead>
  {% endif %}

Example usage

{% embed "@radix/table/table.twig" with {
  header: table.header,
  rows: table.rows,
  header_type: "dark"
} %}
{% endembed %}

Example results

Screenshot of example results

Issue fork radix-3098900

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kentr created an issue. See original summary.

kentr’s picture

Issue summary: View changes
kentr’s picture

Title: Support options for `thead` » Support Bootstrap table header options
kentr’s picture

Status: Active » Needs review
StatusFileSize
new518 bytes

Patch attached.

doxigo’s picture

Status: Needs review » Closed (outdated)

No longer supported/outdated, closing - feel free to open a MR if applicable.

stefan.korn’s picture

Version: 8.x-4.x-dev » 6.0.x-dev
Status: Closed (outdated) » Active

stefan.korn’s picture

Would actually like to see this in current version of Radix, like described at https://getbootstrap.com/docs/5.3/content/tables/#table-head

That said, I suppose the current fixed class of "bg-light" has no effect on the table header style, as it is always overwritten from the basic table style.

stefan.korn’s picture

Status: Active » Needs review
doxigo’s picture

Status: Needs review » Needs work

Hey, thanks for the MR,
table-light and table-dark are Bootstrap 5 table variant classes, while bg-light (which was removed in your MR) is a background utility. These aren't really equivalent, table-light/table-dark apply the proper table-specific styling.

That aside, {% if header_style %} is truthy for any non-empty string. That means if someone passes an invalid or arbitrary value like whatever, it will render class="table-foo" without any validation, which could be okay for utility classes but not for what you are trying to achieve. Ideally you'd want to validate against ['light', 'dark'] with SDC considerations as well

stefan.korn’s picture

Status: Needs work » Needs review

Thanks for super quick reply.

I added validation for "light" and "dark" in Twig and SDC, see updated MR.

As for "bg-light" I intentionally removed this. I suppose it has no effect in Bootstrap 5.3, as the color is always overridden by table classes (even if the table has no color classes) and on the otherhand it would be questionable why this should always be "bg-light".

angel_devoeted’s picture

StatusFileSize
new31 KB
new34.85 KB

Manually tested the latest changes in MR !166.

Passing header_style: 'dark' or 'light' correctly applies the respective classes to the <thead>.

light

dark

I also passed an invalid value to test the schema constraint, and it properly throws an error as expected.

doxigo’s picture

Status: Needs review » Fixed

perfect, thanks guys. Merged

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.