Skip to content

DataGrid: icon-only HeaderTemplate leaves the column unlabelled for screen readers #432

Description

@mathewtaylor

Follow-up from #423, which added HeaderTemplate to BbDataGridPropertyColumn. Pre-existing gap, not introduced by that change — but #423 makes it much easier to hit.

Problem

BbDataGridHeaderCell sets aria-sort, but the <th> carries no aria-label. Its accessible name therefore comes from its own text content. Title is used for the column chooser and the column menu's aria-labels, but it is not a fallback for the header cell itself.

So a header rendered from a template with no text — the icon-only case that HeaderTemplate exists to enable — produces an unlabelled column for screen reader users:

<BbDataGridPropertyColumn Property="x => x.Email" Title="Email">
    <HeaderTemplate>
        <LucideIcon Name="mail" Size="16" />
    </HeaderTemplate>
</BbDataGridPropertyColumn>

The column announces as empty, despite Title="Email" being right there and already being used elsewhere for exactly this purpose.

Current workaround

Consumers must add screen-reader-only text themselves, which is what the demo and the HeaderTemplate docs currently tell them to do:

<HeaderTemplate>
    <LucideIcon Name="mail" Size="16" />
    <span class="sr-only">Email</span>
</HeaderTemplate>

That works, but it puts the burden on the consumer for something the component already knows, and it fails silently when forgotten — nothing in the UI hints that the column is unlabelled.

Proposal

Have the header cell fall back to aria-label="@Title" when a HeaderTemplate is supplied (or, more simply, whenever Title is set and would otherwise not be the cell's text). The information is already there; it just is not reaching the element.

Notes

  • Touches Primitives (BbDataGridHeaderCell), which is why it was kept out of Enhancement: DataGrid PropertyColumn HeaderTemplate #423.
  • Worth checking the same question for BbDataGridTemplateColumn.HeaderTemplate, which has the identical shape and the identical exposure.
  • Care needed not to double-announce when the template does contain text — an aria-label overrides the content, so applying it unconditionally would silence a perfectly good text header and could contradict it. Applying it only when Title is set is probably right, but the behaviour when both Title and template text exist should be decided deliberately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions