mirror of
https://github.com/radzenhq/radzen-blazor.git
synced 2026-07-08 18:16:08 +00:00
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:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
@@ -561,6 +561,11 @@ namespace Radzen.Blazor
|
||||
{
|
||||
isFirstRender = firstRender;
|
||||
|
||||
if (grid != null)
|
||||
{
|
||||
grid.HasActiveDescendant ??= () => selectedIndex >= 0;
|
||||
}
|
||||
|
||||
if (firstRender)
|
||||
{
|
||||
if(Visible && LoadData.HasDelegate && Data == null)
|
||||
|
||||
Reference in New Issue
Block a user