Problem/Motivation
If a column in a view has the option "Add default classes" turned off, then its header and data cells get the same classes as the prior column. This can lead to more than one column seeming to be "active" for sorting, and other possible problems with incorrect classes being applied.
Steps to reproduce
Install the attached view. In the views UI, note that the first field (Title) has "Add default classes" turned on, whereas the second field (Authored On) has it turned off. This results in the Authored On field getting the is-active
class when it should not.
Proposed resolution
The bug occurs twice in the views-view-table.html.twig
that is part of every theme. The first time is:
<tr>
{% for key, column in header %}
{% if column.default_classes %}
{%
set column_classes = [
'views-field',
'views-field-' ~ fields[key],
]
%}
{% endif %}
Because column_classes
is not reset when column.default_classes
(the "Add default classes" option) is turned off, the list of classes is reused from the previous column. The solution is simply to add a line:
<tr>
{% for key, column in header %}
{% set column_classes = [] %} {# ADDED THIS LINE #}
{% if column.default_classes %}
A similar fix must be made further down in the template, where the data cells are generated. The attached patch addresses this problem for all of the themes in core, as well as the default template in Views itself.
It's worth noting that any custom themes that include a version of this template, such as the contrib version of Classy, also need this fix.