Posted by brianbrarian on June 9, 2022 at 9:25pm
Does anyone know whether there's any reason why, when "group by" is used in a view, the headings for the at least the first grouping are formatted as h3?
This can cause accessibility issues, because the page the view is on may not have any h2 headings or the view itself may be under a h3 heading.
An issue was created on d.o more than 10 years ago, but the only solution seems to be overriding templates.
https://www.drupal.org/project/drupal/issues/1383696
I didn't see any explanation there for why Views still does this.
It seems like it ought to be part of the Views UI to be able to select the heading level of the top grouping field.

Comments
I second this question
This is an issue I've been tracking as well. As far as why the heading's statically added to the template rather than providing a choice in the View UI, I don't know either based on the ticket. View fields already provide heading choices in their styling, so it doesn't seem like a stretch to me to extend heading options to grouping as well.
EDIT: since other people have done workarounds to solve the issue, adding a core solution could have an effect on those templates, so theme devs may need a heads up on this kind of change.
My boss and I are interested in finding a solution too, since we're finding this issue in our own view displays and would like to see it fixed in core (rather than even more template overrides). We discussed digging into a fix a few weeks ago, after some table accessibility tickets we were working on were sorted, but I'll see where we're at as far us working on a solution for this issue.
If someone beats us to a solution though, we're happy to test and verify.
Agreed this would be a big
Agreed this would be a big improvement. Many of us can override templates, but many others wouldn't notice it is a problem or wouldn't know how to override templates if they do notice. Core needs to be as accessible as possible out of the box.
Semantic Views module
I just saw something in that d.o issue that I missed before I started this discussion yesterday ...
https://www.drupal.org/project/drupal/issues/1383696#comment-6719374
The Semantic Views contrib module does appear to solve this problem with the "group by" headings, but only if you want your view displayed as an unformatted list or html list. No options in Semantic Views for grid or table or anything else.
https://www.drupal.org/project/semanticviews
Update on proposed fix for issue #1383696
For anyone interested in seeing a core-based solution to the static h3 issue, our web team at Western Washington University has been working on a solution that adds HTML wrapper options to the grouping label. This means a site builder can use the proper heading level for each grouping, or use a non-heading wrapper if semantically that's more appropriate or is grouped for non-semantic reasons.
There's a PHP bug remaining to squash, but locally our team can still get these options working--so for those with a local Drupal test site interested in checking out the working branch, feedback or bug reports are appreciated.