fix(webui): keep sheet close focus rings keyboard-only
This commit is contained in:
1 parent
31b193236f
commit
a721eb8476
2 files changed
+30
-1
No files matched your search
@@ -100,7 +100,7 @@ const SheetContent = React.forwardRef<
|
|||||||
<DialogPrimitive.Close
|
<DialogPrimitive.Close
|
||||||
className={cn(
|
className={cn(
|
||||||
"absolute right-4 top-4 rounded-mark opacity-70 ring-offset-background transition-opacity",
|
"absolute right-4 top-4 rounded-mark opacity-70 ring-offset-background transition-opacity",
|
||||||
"hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
"hover:opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
||||||
"disabled:pointer-events-none",
|
"disabled:pointer-events-none",
|
||||||
closeButtonClassName,
|
closeButtonClassName,
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { render, screen, waitFor, within } from "@testing-library/react";
|
||||||
|
import userEvent from "@testing-library/user-event";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { Sheet, SheetContent, SheetDescription, SheetTitle, SheetTrigger } from "@/components/ui/sheet";
|
||||||
|
|
||||||
|
describe("sheet close button", () => {
|
||||||
|
it("reserves the focus ring for keyboard navigation and restores focus after closing", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
render(<Sheet>
|
||||||
|
<SheetTrigger>Open details</SheetTrigger>
|
||||||
|
<SheetContent>
|
||||||
|
<SheetTitle>Task details</SheetTitle>
|
||||||
|
<SheetDescription>Delegated task</SheetDescription>
|
||||||
|
</SheetContent>
|
||||||
|
</Sheet>);
|
||||||
|
|
||||||
|
const trigger = screen.getByRole("button", { name: "Open details" });
|
||||||
|
await user.click(trigger);
|
||||||
|
const dialog = screen.getByRole("dialog", { name: "Task details" });
|
||||||
|
const close = within(dialog).getByRole("button", { name: "Close" });
|
||||||
|
expect(close).toHaveClass("focus-visible:ring-2", "focus-visible:ring-ring", "focus-visible:ring-offset-2");
|
||||||
|
expect(close).not.toHaveClass("focus:ring-2");
|
||||||
|
|
||||||
|
await user.click(close);
|
||||||
|
await waitFor(() => expect(trigger).toHaveFocus());
|
||||||
|
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user