test(centralui): TreeView keyboard-activation test + document preventDefault scope (T36a review)
This commit is contained in:
@@ -59,6 +59,9 @@ else
|
||||
@onclick="() => ToggleExpand(key)"
|
||||
@onclick:stopPropagation
|
||||
@onkeydown="(e) => OnToggleKey(e, key)"
|
||||
@* preventDefault suppresses Space-bar page scroll on activation (intended for a role=button).
|
||||
It also suppresses Arrow-key default scroll while the toggle itself has focus — acceptable,
|
||||
as the chevron is Tab-navigated and Blazor offers no per-key conditional preventDefault. *@
|
||||
@onkeydown:preventDefault><i class="bi bi-chevron-right"></i></span>
|
||||
}
|
||||
else
|
||||
|
||||
@@ -88,6 +88,38 @@ public class AccessibilityTests : BunitContext
|
||||
Assert.StartsWith("Collapse", labelAfterExpand!);
|
||||
}
|
||||
|
||||
// ── Test 3: TreeView keyboard activation (Enter / Space) ──────────────────
|
||||
|
||||
[Fact]
|
||||
public void TreeViewToggle_EnterKey_TogglesExpanded()
|
||||
{
|
||||
var cut = RenderTreeView();
|
||||
|
||||
var toggle = cut.Find(".tv-toggle");
|
||||
Assert.Equal("false", toggle.GetAttribute("aria-expanded"));
|
||||
|
||||
// Fire Enter on the toggle — should expand the branch.
|
||||
toggle.TriggerEvent("onkeydown", new Microsoft.AspNetCore.Components.Web.KeyboardEventArgs { Key = "Enter" });
|
||||
|
||||
var expandedToggle = cut.Find(".tv-toggle");
|
||||
Assert.Equal("true", expandedToggle.GetAttribute("aria-expanded"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TreeViewToggle_SpaceKey_TogglesExpanded()
|
||||
{
|
||||
var cut = RenderTreeView();
|
||||
|
||||
var toggle = cut.Find(".tv-toggle");
|
||||
Assert.Equal("false", toggle.GetAttribute("aria-expanded"));
|
||||
|
||||
// Fire Space on the toggle — should expand the branch.
|
||||
toggle.TriggerEvent("onkeydown", new Microsoft.AspNetCore.Components.Web.KeyboardEventArgs { Key = " " });
|
||||
|
||||
var expandedToggle = cut.Find(".tv-toggle");
|
||||
Assert.Equal("true", expandedToggle.GetAttribute("aria-expanded"));
|
||||
}
|
||||
|
||||
// ── Test 2: ToastNotification live-region regression lock ─────────────────
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user