diff --git a/Radzen.Blazor.Tests/DataGridTests.cs b/Radzen.Blazor.Tests/DataGridTests.cs index ed488796c..ca64ef302 100644 --- a/Radzen.Blazor.Tests/DataGridTests.cs +++ b/Radzen.Blazor.Tests/DataGridTests.cs @@ -3273,5 +3273,43 @@ namespace Radzen.Blazor.Tests Assert.Equal("0", wrapper.GetAttribute("tabindex")); Assert.False(string.IsNullOrEmpty(wrapper.GetAttribute("aria-activedescendant"))); } + + [Fact] + public void DataGrid_AppliesAriaGridRolesToTableDescendants() + { + using var ctx = new TestContext(); + ctx.JSInterop.Mode = JSRuntimeMode.Loose; + ctx.JSInterop.SetupModule("_content/Radzen.Blazor/Radzen.Blazor.js"); + + var component = ctx.RenderComponent>(parameterBuilder => + { + parameterBuilder.Add>(p => p.Data, new[] { new { Id = 1 }, new { Id = 2 } }); + parameterBuilder.Add(p => p.Columns, builder => + { + builder.OpenComponent(0, typeof(RadzenDataGridColumn)); + builder.AddAttribute(1, "Property", "Id"); + builder.CloseComponent(); + }); + }); + + Assert.Equal("presentation", component.Find("table.rz-grid-table").GetAttribute("role")); + Assert.Equal("rowgroup", component.Find("thead").GetAttribute("role")); + Assert.Equal("rowgroup", component.Find("tbody").GetAttribute("role")); + + var headerCell = component.Find("thead tr th"); + Assert.Equal("row", headerCell.ParentElement!.GetAttribute("role")); + Assert.Equal("columnheader", headerCell.GetAttribute("role")); + + var dataRows = component.FindAll("tbody tr"); + Assert.NotEmpty(dataRows); + foreach (var row in dataRows) + { + Assert.Equal("row", row.GetAttribute("role")); + foreach (var cell in row.QuerySelectorAll("td")) + { + Assert.Equal("gridcell", cell.GetAttribute("role")); + } + } + } } } diff --git a/Radzen.Blazor/RadzenDataGrid.razor b/Radzen.Blazor/RadzenDataGrid.razor index 779c1a219..4e35a9cc1 100644 --- a/Radzen.Blazor/RadzenDataGrid.razor +++ b/Radzen.Blazor/RadzenDataGrid.razor @@ -83,7 +83,7 @@ }
- c.Parent != null) ? "rz-grid-table-composite" : "") @(getGridLinesCSSClass())"> +
c.Parent != null) ? "rz-grid-table-composite" : "") @(getGridLinesCSSClass())"> @if(allColumns.All(c => c.Parent == null)) { @@ -104,26 +104,26 @@ } } - + @if (ShowHeader) { @for (var i = 0; i < deepestChildColumnLevel + 1; i++) { - + @if (i == 0) // Only add the th elements for the first row { @if (ShowGroupExpandColumn) { @foreach (var g in Groups) { - } } @if (Template != null && ShowExpandColumn && i == 0) { - + @if (ShowGroupExpandColumn) { @foreach (var g in Groups) { - } } @if (Template != null && ShowExpandColumn ) { - } @foreach (var column in visibleColumns) { var filterMode = column.FilterMode ?? FilterMode; - } - + @if (Data != null) { @if (!ShowEmptyMessage || Count > 0 && (IsVirtualizationAllowed() ? Count > 0 && Data.Count() > 0 : true) || LoadData.HasDelegate && Data.Count() > 0 || itemsToInsert.Count > 0) @@ -209,8 +209,8 @@ } else { - - + - + @if (allColumns.Where(c => c.Visible && c.FooterTemplate != null).Any()) { - + @for (var i = 0; i < deepestChildColumnLevel + 1; i++) { - + @if (i == 0) // Only add the th elements for the first row { @if (ShowGroupExpandColumn) { @foreach (var g in Groups) { - } } @if (Template != null && ShowExpandColumn && i == 0) { - } @@ -621,7 +621,7 @@ @if (this.AllowCompositeDataCells ? RowIndex == column.GetLevel() : (column.Parent != null && RowIndex == column.GetLevel() || column.Columns == null)) { - + @if (i == 0) // Only add the th elements for the first row { @if (Grid.Template != null && Grid.ShowExpandColumn) { - } } @for (var j = 0; j < GetLevel() + (Grid.ShowGroupExpandColumn ? 0 : -1) + Grid.Groups.Count - GetLevel(); j++) { - } diff --git a/Radzen.Blazor/RadzenDataGridGroupRow.razor b/Radzen.Blazor/RadzenDataGridGroupRow.razor index 57c6f0661..9bc93647d 100644 --- a/Radzen.Blazor/RadzenDataGridGroupRow.razor +++ b/Radzen.Blazor/RadzenDataGridGroupRow.razor @@ -11,20 +11,20 @@ } } } - + @if (Grid != null && Grid.ShowGroupExpandColumn) { @if (Group.GroupDescriptor != null) { @for (var i = 0; i < GetLevel(); i++) { - } } - } - + @if (Grid?.ShowGroupExpandColumn == true) { @foreach(var g in Grid.Groups) { @if (i == firstLevel) { - } - + } } @if (Grid?.Template != null && Grid?.ShowExpandColumn == true && i == firstLevel) { - - + - +