Name dialogs and contain native overlay keyboard focus

This commit is contained in:
Joseph Doherty
2026-11-13 17:42:14 -05:00
parent cdd3adf6fc
commit 87c882ec0a
46 changed files with 1353 additions and 119 deletions
@@ -33,6 +33,21 @@ public class AuditDrilldownDrawerTests : BunitContext
JSInterop.Mode = JSRuntimeMode.Loose;
}
/// <summary>The drawer has modal semantics and Escape dispatches close once.</summary>
[Fact]
public void OpenDrawer_HasNamedModalAndEscapeCloses()
{
var closes = 0;
var cut = Render<AuditDrilldownDrawer>(p => p.Add(c => c.Event, MakeEvent())
.Add(c => c.IsOpen, true).Add(c => c.OnClose, () => closes++));
var dialog = cut.Find("[role=dialog]");
Assert.Equal("true", dialog.GetAttribute("aria-modal"));
var titleId = dialog.GetAttribute("aria-labelledby");
Assert.Contains("Audit Event", cut.Find("#" + titleId).TextContent);
dialog.KeyDown(new Microsoft.AspNetCore.Components.Web.KeyboardEventArgs { Key = "Escape" });
Assert.Equal(1, closes);
}
private static AuditEventView MakeEvent(
AuditChannel channel = AuditChannel.ApiOutbound,
AuditKind kind = AuditKind.ApiCall,
@@ -372,6 +387,8 @@ public class AuditDrilldownDrawerTests : BunitContext
{
// Set up Strict mode interop so the call must match exactly.
JSInterop.Mode = JSRuntimeMode.Strict;
JSInterop.Setup<bool?>("sbDialog.activate", _ => true).SetResult(true);
JSInterop.SetupVoid("sbDialog.deactivate", _ => true).SetVoidResult();
var clipboardCall = JSInterop.SetupVoid(
"navigator.clipboard.writeText",
invocation => invocation.Arguments.Count == 1