DropDownDataGrid: clear grid aria-activedescendant when no row is active

Gate RadzenDataGrid.GetActiveDescendantId via an optional HasActiveDescendant
override so the grid popup no longer points aria-activedescendant at a
non-existent {id}-active-item id when selectedIndex is -1 (initial render or
after filtering). RadzenDropDownDataGrid wires the override to its selectedIndex
in OnAfterRenderAsync. Standalone RadzenDataGrid behavior is unchanged (override
unset).
This commit is contained in:
Vladimir Enchev
2026-06-30 16:32:04 +03:00
parent 8f1464f340
commit 3c19f06ba7
3 changed files with 41 additions and 0 deletions

View File

@@ -3447,6 +3447,35 @@ namespace Radzen.Blazor.Tests
Assert.False(string.IsNullOrEmpty(wrapper.GetAttribute("aria-activedescendant")));
}
[Fact]
public void DataGrid_ActiveDescendant_IsClearedWhenNoActiveRow()
{
using var ctx = new TestContext();
ctx.JSInterop.Mode = JSRuntimeMode.Loose;
ctx.JSInterop.SetupModule("_content/Radzen.Blazor/Radzen.Blazor.js");
var component = ctx.RenderComponent<RadzenDataGrid<dynamic>>(parameterBuilder =>
{
parameterBuilder.Add<IEnumerable<dynamic>>(p => p.Data, new[] { new { Id = 1 }, new { Id = 2 } });
parameterBuilder.Add<RenderFragment>(p => p.Columns, builder =>
{
builder.OpenComponent(0, typeof(RadzenDataGridColumn<dynamic>));
builder.AddAttribute(1, "Property", "Id");
builder.CloseComponent();
});
});
var instance = component.Instance;
Assert.False(string.IsNullOrEmpty(instance.GetActiveDescendantId()));
instance.HasActiveDescendant = () => false;
Assert.Null(instance.GetActiveDescendantId());
instance.HasActiveDescendant = () => true;
Assert.False(string.IsNullOrEmpty(instance.GetActiveDescendantId()));
}
[Fact]
public void DataGrid_AppliesAriaGridRolesToTableDescendants()
{

View File

@@ -598,8 +598,15 @@ namespace Radzen.Blazor
int focusedIndex = -1;
int focusedCellIndex;
internal Func<bool>? HasActiveDescendant { get; set; }
internal string? GetActiveDescendantId()
{
if (HasActiveDescendant != null && !HasActiveDescendant())
{
return null;
}
return $"{GetId()}-active-item";
}

View File

@@ -561,6 +561,11 @@ namespace Radzen.Blazor
{
isFirstRender = firstRender;
if (grid != null)
{
grid.HasActiveDescendant ??= () => selectedIndex >= 0;
}
if (firstRender)
{
if(Visible && LoadData.HasDelegate && Data == null)