fix(webui): prevent mobile sidebar tooltip and double-tap navigation
Integrate the focused Sheet autofocus and touch hover corrections from #5777 and #5641 on current main. Preserve caller focus overrides, keyboard accessibility, and the existing viewport/safe-area policy. Add App-level coverage for consecutive one-click topic selections and drawer dismissal alongside focus and emitted-CSS regressions. Co-authored-by: Nikko Gonzales <nikkoxgonzales@gmail.com> Co-authored-by: moran <moranfong@gmail.com>
This commit is contained in:
1 parent
d37d7c07c0
commit
13319dfe15
6 files changed
+265
-17
No files matched your search
@@ -962,7 +962,7 @@ export const ChatList = memo(function ChatList({
|
|||||||
compact ? "min-h-7" : "min-h-8",
|
compact ? "min-h-7" : "min-h-8",
|
||||||
topicActive
|
topicActive
|
||||||
? "text-sidebar-foreground"
|
? "text-sidebar-foreground"
|
||||||
: "text-sidebar-content hover:text-sidebar-accent-foreground",
|
: "text-sidebar-content media-hover:hover:text-sidebar-accent-foreground",
|
||||||
deleteSelectionMode && (tabSelected || tabPartiallySelected)
|
deleteSelectionMode && (tabSelected || tabPartiallySelected)
|
||||||
&& "bg-sidebar-accent/55 text-sidebar-accent-foreground",
|
&& "bg-sidebar-accent/55 text-sidebar-accent-foreground",
|
||||||
)}
|
)}
|
||||||
@@ -1049,7 +1049,7 @@ export const ChatList = memo(function ChatList({
|
|||||||
<DropdownMenuTrigger
|
<DropdownMenuTrigger
|
||||||
className={cn(
|
className={cn(
|
||||||
"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-sidebar-muted-foreground opacity-0 transition-opacity",
|
"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-sidebar-muted-foreground opacity-0 transition-opacity",
|
||||||
"hover:bg-sidebar-accent hover:text-sidebar-foreground group-hover:opacity-100",
|
"media-hover:hover:bg-sidebar-accent media-hover:hover:text-sidebar-foreground media-hover:group-hover:opacity-100",
|
||||||
"focus-visible:opacity-100 data-[state=open]:opacity-100",
|
"focus-visible:opacity-100 data-[state=open]:opacity-100",
|
||||||
)}
|
)}
|
||||||
aria-label={t("chat.actions", { title })}
|
aria-label={t("chat.actions", { title })}
|
||||||
@@ -1143,7 +1143,7 @@ export const ChatList = memo(function ChatList({
|
|||||||
Math.min(totalSessionCount, limit + VISIBLE_SESSIONS_INCREMENT),
|
Math.min(totalSessionCount, limit + VISIBLE_SESSIONS_INCREMENT),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
className="h-8 w-full rounded-full text-[12px] font-medium text-sidebar-muted-foreground transition-colors hover:bg-sidebar-accent/65 hover:text-sidebar-muted-foreground"
|
className="h-8 w-full rounded-full text-[12px] font-medium text-sidebar-muted-foreground transition-colors media-hover:hover:bg-sidebar-accent/65 media-hover:hover:text-sidebar-muted-foreground"
|
||||||
>
|
>
|
||||||
{t("chat.showMore", { count: hiddenSessionCount })}
|
{t("chat.showMore", { count: hiddenSessionCount })}
|
||||||
</button>
|
</button>
|
||||||
@@ -1160,7 +1160,7 @@ export const ChatList = memo(function ChatList({
|
|||||||
aria-label={t("chat.cancelSelection", {
|
aria-label={t("chat.cancelSelection", {
|
||||||
defaultValue: "Cancel selection",
|
defaultValue: "Cancel selection",
|
||||||
})}
|
})}
|
||||||
className="inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full text-sidebar-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground"
|
className="inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full text-sidebar-muted-foreground transition-colors media-hover:hover:bg-accent/60 media-hover:hover:text-foreground"
|
||||||
>
|
>
|
||||||
<X className="h-4 w-4" aria-hidden />
|
<X className="h-4 w-4" aria-hidden />
|
||||||
</button>
|
</button>
|
||||||
@@ -1174,7 +1174,7 @@ export const ChatList = memo(function ChatList({
|
|||||||
type="button"
|
type="button"
|
||||||
disabled={selectedDeleteKeys.size === 0}
|
disabled={selectedDeleteKeys.size === 0}
|
||||||
onClick={confirmDeleteSelection}
|
onClick={confirmDeleteSelection}
|
||||||
className="inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full bg-destructive px-3 text-[12px] font-semibold text-destructive-foreground transition-colors hover:bg-destructive/90 disabled:pointer-events-none disabled:opacity-40"
|
className="inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full bg-destructive px-3 text-[12px] font-semibold text-destructive-foreground transition-colors media-hover:hover:bg-destructive/90 disabled:pointer-events-none disabled:opacity-40"
|
||||||
>
|
>
|
||||||
<Trash2 className="h-3.5 w-3.5" aria-hidden />
|
<Trash2 className="h-3.5 w-3.5" aria-hidden />
|
||||||
{t("chat.deleteSelected", { defaultValue: "Delete" })}
|
{t("chat.deleteSelected", { defaultValue: "Delete" })}
|
||||||
@@ -1246,7 +1246,7 @@ function WorkbenchTabHeader({
|
|||||||
className={cn(
|
className={cn(
|
||||||
"relative inline-flex h-6 w-3.5 shrink-0 items-center justify-center rounded-md before:absolute before:-inset-x-1 before:inset-y-0",
|
"relative inline-flex h-6 w-3.5 shrink-0 items-center justify-center rounded-md before:absolute before:-inset-x-1 before:inset-y-0",
|
||||||
"text-sidebar-muted-foreground transition-[background-color,color,transform] duration-150 ease-out",
|
"text-sidebar-muted-foreground transition-[background-color,color,transform] duration-150 ease-out",
|
||||||
"hover:bg-sidebar-accent hover:text-sidebar-foreground active:scale-[0.96]",
|
"media-hover:hover:bg-sidebar-accent media-hover:hover:text-sidebar-foreground active:scale-[0.96]",
|
||||||
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60",
|
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60",
|
||||||
"motion-reduce:transition-none motion-reduce:active:scale-100",
|
"motion-reduce:transition-none motion-reduce:active:scale-100",
|
||||||
)}
|
)}
|
||||||
@@ -1297,7 +1297,7 @@ function WorkbenchTabHeader({
|
|||||||
className={cn(
|
className={cn(
|
||||||
"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md",
|
"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md",
|
||||||
"text-sidebar-muted-foreground opacity-0 transition-opacity",
|
"text-sidebar-muted-foreground opacity-0 transition-opacity",
|
||||||
"hover:bg-sidebar-accent hover:text-sidebar-foreground group-hover/tab:opacity-100",
|
"media-hover:hover:bg-sidebar-accent media-hover:hover:text-sidebar-foreground media-hover:group-hover/tab:opacity-100",
|
||||||
"focus-visible:opacity-100 data-[state=open]:opacity-100",
|
"focus-visible:opacity-100 data-[state=open]:opacity-100",
|
||||||
)}
|
)}
|
||||||
aria-label={t("chat.actions", { title })}
|
aria-label={t("chat.actions", { title })}
|
||||||
@@ -1441,7 +1441,7 @@ function ActivePaneRows({
|
|||||||
compact ? "min-h-7" : "min-h-8",
|
compact ? "min-h-7" : "min-h-8",
|
||||||
active
|
active
|
||||||
? "text-sidebar-foreground"
|
? "text-sidebar-foreground"
|
||||||
: "text-sidebar-content hover:text-sidebar-accent-foreground",
|
: "text-sidebar-content media-hover:hover:text-sidebar-accent-foreground",
|
||||||
deleteSelectionMode && selected
|
deleteSelectionMode && selected
|
||||||
&& "bg-sidebar-accent/55 text-sidebar-accent-foreground",
|
&& "bg-sidebar-accent/55 text-sidebar-accent-foreground",
|
||||||
)}
|
)}
|
||||||
@@ -1492,7 +1492,7 @@ function ActivePaneRows({
|
|||||||
<DropdownMenuTrigger
|
<DropdownMenuTrigger
|
||||||
className={cn(
|
className={cn(
|
||||||
"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-sidebar-muted-foreground opacity-0 transition-opacity",
|
"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-sidebar-muted-foreground opacity-0 transition-opacity",
|
||||||
"hover:bg-sidebar-accent hover:text-sidebar-foreground group-hover/pane:opacity-100",
|
"media-hover:hover:bg-sidebar-accent media-hover:hover:text-sidebar-foreground media-hover:group-hover/pane:opacity-100",
|
||||||
"focus-visible:opacity-100 data-[state=open]:opacity-100",
|
"focus-visible:opacity-100 data-[state=open]:opacity-100",
|
||||||
)}
|
)}
|
||||||
aria-label={paneActionsLabel}
|
aria-label={paneActionsLabel}
|
||||||
@@ -1657,7 +1657,7 @@ function TemporaryChatSection({
|
|||||||
SIDEBAR_SELECTION_ITEM_CLASS,
|
SIDEBAR_SELECTION_ITEM_CLASS,
|
||||||
active
|
active
|
||||||
? "text-sidebar-accent-foreground"
|
? "text-sidebar-accent-foreground"
|
||||||
: "text-sidebar-content settings-hover hover:text-sidebar-accent-foreground",
|
: "text-sidebar-content settings-hover media-hover:hover:text-sidebar-accent-foreground",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
@@ -1680,7 +1680,7 @@ function TemporaryChatSection({
|
|||||||
type="button"
|
type="button"
|
||||||
aria-label={t("temporaryChat.closeAction", { title })}
|
aria-label={t("temporaryChat.closeAction", { title })}
|
||||||
onClick={() => onClose(session.key)}
|
onClick={() => onClose(session.key)}
|
||||||
className="inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-sidebar-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60"
|
className="inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-sidebar-muted-foreground transition-colors media-hover:hover:bg-destructive/10 media-hover:hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60"
|
||||||
>
|
>
|
||||||
<X className="h-3.5 w-3.5" aria-hidden />
|
<X className="h-3.5 w-3.5" aria-hidden />
|
||||||
</button>
|
</button>
|
||||||
@@ -1726,7 +1726,7 @@ function ProjectGroupHeader({
|
|||||||
aria-expanded={!collapsed}
|
aria-expanded={!collapsed}
|
||||||
onClick={onToggle}
|
onClick={onToggle}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex min-w-0 flex-1 items-center gap-2 rounded-lg py-1 text-left transition-colors hover:text-sidebar-foreground",
|
"flex min-w-0 flex-1 items-center gap-2 rounded-lg py-1 text-left transition-colors media-hover:hover:text-sidebar-foreground",
|
||||||
active ? "font-medium text-sidebar-foreground" : "font-normal",
|
active ? "font-medium text-sidebar-foreground" : "font-normal",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@@ -1751,7 +1751,7 @@ function ProjectGroupHeader({
|
|||||||
className={cn(
|
className={cn(
|
||||||
"relative inline-flex h-6 w-3.5 shrink-0 items-center justify-center rounded-md before:absolute before:-inset-x-1 before:inset-y-0",
|
"relative inline-flex h-6 w-3.5 shrink-0 items-center justify-center rounded-md before:absolute before:-inset-x-1 before:inset-y-0",
|
||||||
"text-sidebar-muted-foreground transition-[background-color,color,transform] duration-150 ease-out",
|
"text-sidebar-muted-foreground transition-[background-color,color,transform] duration-150 ease-out",
|
||||||
"hover:bg-sidebar-accent hover:text-sidebar-foreground active:scale-[0.96]",
|
"media-hover:hover:bg-sidebar-accent media-hover:hover:text-sidebar-foreground active:scale-[0.96]",
|
||||||
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60",
|
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60",
|
||||||
"motion-reduce:transition-none motion-reduce:active:scale-100",
|
"motion-reduce:transition-none motion-reduce:active:scale-100",
|
||||||
)}
|
)}
|
||||||
@@ -1788,7 +1788,7 @@ function ProjectGroupHeader({
|
|||||||
<DropdownMenuTrigger
|
<DropdownMenuTrigger
|
||||||
className={cn(
|
className={cn(
|
||||||
"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-sidebar-muted-foreground opacity-0 transition-opacity",
|
"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-sidebar-muted-foreground opacity-0 transition-opacity",
|
||||||
"hover:bg-sidebar-accent hover:text-sidebar-foreground group-hover:opacity-100 focus-visible:opacity-100",
|
"media-hover:hover:bg-sidebar-accent media-hover:hover:text-sidebar-foreground media-hover:group-hover:opacity-100 focus-visible:opacity-100",
|
||||||
"data-[state=open]:opacity-100",
|
"data-[state=open]:opacity-100",
|
||||||
)}
|
)}
|
||||||
aria-label={t("chat.actions", { title: label })}
|
aria-label={t("chat.actions", { title: label })}
|
||||||
@@ -1861,7 +1861,7 @@ function ChatsFoldFooter({
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={onToggle}
|
onClick={onToggle}
|
||||||
className="h-7 w-full rounded-xl text-left text-[12px] font-medium text-sidebar-muted-foreground transition-colors hover:bg-sidebar-accent/50 hover:text-sidebar-muted-foreground"
|
className="h-7 w-full rounded-xl text-left text-[12px] font-medium text-sidebar-muted-foreground transition-colors media-hover:hover:bg-sidebar-accent/50 media-hover:hover:text-sidebar-muted-foreground"
|
||||||
>
|
>
|
||||||
<span className="px-2">
|
<span className="px-2">
|
||||||
{folded
|
{folded
|
||||||
|
|||||||
@@ -74,16 +74,33 @@ const SheetContent = React.forwardRef<
|
|||||||
children,
|
children,
|
||||||
closeButtonClassName,
|
closeButtonClassName,
|
||||||
showCloseButton = true,
|
showCloseButton = true,
|
||||||
|
onOpenAutoFocus,
|
||||||
...props
|
...props
|
||||||
},
|
},
|
||||||
ref,
|
ref,
|
||||||
) => {
|
) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const contentNode = React.useRef<HTMLDivElement | null>(null);
|
||||||
|
const contentRef = React.useCallback(
|
||||||
|
(node: HTMLDivElement | null) => {
|
||||||
|
contentNode.current = node;
|
||||||
|
if (typeof ref === "function") ref(node);
|
||||||
|
else if (ref) ref.current = node;
|
||||||
|
},
|
||||||
|
[ref],
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<SheetPortal>
|
<SheetPortal>
|
||||||
<SheetOverlay />
|
<SheetOverlay />
|
||||||
<DialogPrimitive.Content
|
<DialogPrimitive.Content
|
||||||
ref={ref}
|
ref={contentRef}
|
||||||
|
onOpenAutoFocus={(event) => {
|
||||||
|
if (onOpenAutoFocus) onOpenAutoFocus(event);
|
||||||
|
else {
|
||||||
|
event.preventDefault();
|
||||||
|
contentNode.current?.focus({ preventScroll: true });
|
||||||
|
}
|
||||||
|
}}
|
||||||
className={cn(
|
className={cn(
|
||||||
sheetVariants({ side }),
|
sheetVariants({ side }),
|
||||||
"data-[state=open]:animate-in data-[state=closed]:animate-out",
|
"data-[state=open]:animate-in data-[state=closed]:animate-out",
|
||||||
|
|||||||
@@ -2199,6 +2199,42 @@ describe("App layout", () => {
|
|||||||
expect(screen.queryByText("Daily repo check")).not.toBeInTheDocument();
|
expect(screen.queryByText("Daily repo check")).not.toBeInTheDocument();
|
||||||
}, 15_000);
|
}, 15_000);
|
||||||
|
|
||||||
|
it("opens a mobile topic with one click and closes the drawer without a search tooltip", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
mockSessions = ["First", "Second"].map((title, index) => ({
|
||||||
|
key: `websocket:mobile-${index}`,
|
||||||
|
channel: "websocket",
|
||||||
|
chatId: `mobile-${index}`,
|
||||||
|
createdAt: "2026-04-16T10:00:00Z",
|
||||||
|
updatedAt: "2026-04-16T10:00:00Z",
|
||||||
|
preview: `${title} mobile chat`,
|
||||||
|
}));
|
||||||
|
vi.stubGlobal("matchMedia", vi.fn().mockImplementation((query: string) => ({
|
||||||
|
matches: !query.includes("1024px"),
|
||||||
|
media: query,
|
||||||
|
onchange: null,
|
||||||
|
addListener: vi.fn(),
|
||||||
|
removeListener: vi.fn(),
|
||||||
|
addEventListener: vi.fn(),
|
||||||
|
removeEventListener: vi.fn(),
|
||||||
|
dispatchEvent: vi.fn(),
|
||||||
|
})));
|
||||||
|
|
||||||
|
render(<App />);
|
||||||
|
await waitFor(() => expect(connectSpy).toHaveBeenCalled());
|
||||||
|
for (const title of ["First", "Second"]) {
|
||||||
|
await user.click(await screen.findByRole("button", { name: "Toggle sidebar" }));
|
||||||
|
const sheet = await screen.findByRole("dialog");
|
||||||
|
await waitFor(() => expect(sheet).toHaveFocus());
|
||||||
|
expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
|
||||||
|
await user.click(await within(sheet).findByRole("button", { name: `${title} mobile chat` }));
|
||||||
|
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||||
|
await waitFor(() => expect(document.title).toBe(`${title} mobile chat · nanobot`));
|
||||||
|
expect(screen.getByRole("button", { name: `${title} mobile chat` }))
|
||||||
|
.toHaveAttribute("aria-current", "page");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it("keeps the mobile session action menu inside the sidebar sheet", async () => {
|
it("keeps the mobile session action menu inside the sidebar sheet", async () => {
|
||||||
mockSessions = [
|
mockSessions = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
import { render, screen, waitFor, within } from "@testing-library/react";
|
||||||
|
import userEvent from "@testing-library/user-event";
|
||||||
|
import { createRef, type Ref } from "react";
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
import { Sheet, SheetContent, SheetTitle, SheetTrigger } from "@/components/ui/sheet";
|
||||||
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||||
|
|
||||||
|
vi.mock("@/providers/ClientProvider", () => ({
|
||||||
|
useClient: () => ({ client: { status: "idle", onStatus: () => () => {} } }),
|
||||||
|
}));
|
||||||
|
|
||||||
|
function noop() {}
|
||||||
|
|
||||||
|
// Reproduces the #5770 chain: the mobile drawer autofocuses the search button
|
||||||
|
// (Radix focus-scope default), and focusing a tooltip trigger with no preceding
|
||||||
|
// pointerdown opens its tooltip.
|
||||||
|
function DrawerWithSearchTooltip(props: {
|
||||||
|
onOpenAutoFocus?: (event: Event) => void;
|
||||||
|
contentRef?: Ref<HTMLDivElement>;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<TooltipProvider>
|
||||||
|
<Sheet open onOpenChange={noop}>
|
||||||
|
<SheetContent
|
||||||
|
ref={props.contentRef}
|
||||||
|
side="left"
|
||||||
|
showCloseButton={false}
|
||||||
|
aria-describedby={undefined}
|
||||||
|
onOpenAutoFocus={props.onOpenAutoFocus}
|
||||||
|
>
|
||||||
|
<SheetTitle className="sr-only">Navigation</SheetTitle>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<button type="button">search</button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent side="bottom">Search tip</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</SheetContent>
|
||||||
|
</Sheet>
|
||||||
|
</TooltipProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("SheetContent autofocus", () => {
|
||||||
|
// happy-dom reports tabIndex -1 for natively focusable elements without an
|
||||||
|
// explicit tabindex attribute (browsers report 0), which makes Radix
|
||||||
|
// getTabbableCandidates() find nothing. Stub browser behavior so the
|
||||||
|
// autofocus path under test actually runs.
|
||||||
|
const tabIndexDesc = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "tabIndex");
|
||||||
|
beforeEach(() => {
|
||||||
|
Object.defineProperty(HTMLElement.prototype, "tabIndex", {
|
||||||
|
configurable: true,
|
||||||
|
get(this: HTMLElement): number {
|
||||||
|
const attr = this.getAttribute("tabindex");
|
||||||
|
if (attr !== null) return Number(attr);
|
||||||
|
if (/^(BUTTON|A|INPUT|SELECT|TEXTAREA)$/.test(this.tagName)) return 0;
|
||||||
|
return -1;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
afterEach(() => {
|
||||||
|
if (tabIndexDesc) Object.defineProperty(HTMLElement.prototype, "tabIndex", tabIndexDesc);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not steal focus into the search button or pop its tooltip on open (#5770)", async () => {
|
||||||
|
render(<DrawerWithSearchTooltip />);
|
||||||
|
const dialog = await screen.findByRole("dialog");
|
||||||
|
await waitFor(() => expect(dialog).toHaveFocus());
|
||||||
|
const searchButton = within(dialog).getByRole("button", { name: "search" });
|
||||||
|
expect(searchButton).not.toHaveFocus();
|
||||||
|
expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("honors a caller-supplied onOpenAutoFocus handler", async () => {
|
||||||
|
const onOpenAutoFocus = vi.fn((event: Event) => event.preventDefault());
|
||||||
|
render(<DrawerWithSearchTooltip onOpenAutoFocus={onOpenAutoFocus} />);
|
||||||
|
await screen.findByRole("dialog");
|
||||||
|
await waitFor(() => expect(onOpenAutoFocus).toHaveBeenCalled());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps the caller's explicit focus target", async () => {
|
||||||
|
render(<DrawerWithSearchTooltip onOpenAutoFocus={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
screen.getByRole("button", { name: "search" }).focus();
|
||||||
|
}} />);
|
||||||
|
await waitFor(() => expect(screen.getByRole("button", { name: "search" })).toHaveFocus());
|
||||||
|
expect(await screen.findByRole("tooltip")).toHaveTextContent("Search tip");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows callers to retain Radix's default autofocus", async () => {
|
||||||
|
render(<DrawerWithSearchTooltip onOpenAutoFocus={noop} />);
|
||||||
|
await waitFor(() => expect(screen.getByRole("button", { name: "search" })).toHaveFocus());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves object refs while focusing the container", async () => {
|
||||||
|
const ref = createRef<HTMLDivElement>();
|
||||||
|
const { unmount } = render(<DrawerWithSearchTooltip contentRef={ref} />);
|
||||||
|
const dialog = await screen.findByRole("dialog");
|
||||||
|
await waitFor(() => expect(dialog).toHaveFocus());
|
||||||
|
expect(ref.current).toBe(dialog);
|
||||||
|
unmount();
|
||||||
|
expect(ref.current).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves callback refs on mount and unmount", async () => {
|
||||||
|
const ref = vi.fn();
|
||||||
|
const { unmount } = render(<DrawerWithSearchTooltip contentRef={ref} />);
|
||||||
|
const dialog = await screen.findByRole("dialog");
|
||||||
|
await waitFor(() => expect(dialog).toHaveFocus());
|
||||||
|
expect(ref).toHaveBeenCalledWith(dialog);
|
||||||
|
unmount();
|
||||||
|
expect(ref).toHaveBeenLastCalledWith(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps keyboard focus inside the drawer and restores it on Escape", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
render(
|
||||||
|
<Sheet>
|
||||||
|
<SheetTrigger>Open drawer</SheetTrigger>
|
||||||
|
<SheetContent showCloseButton={false} aria-describedby={undefined}>
|
||||||
|
<SheetTitle>Navigation</SheetTitle>
|
||||||
|
<button>First action</button>
|
||||||
|
<button>Last action</button>
|
||||||
|
</SheetContent>
|
||||||
|
</Sheet>,
|
||||||
|
);
|
||||||
|
const trigger = screen.getByRole("button", { name: "Open drawer" });
|
||||||
|
await user.click(trigger);
|
||||||
|
await waitFor(() => expect(screen.getByRole("dialog")).toHaveFocus());
|
||||||
|
await user.tab();
|
||||||
|
expect(screen.getByRole("button", { name: "First action" })).toHaveFocus();
|
||||||
|
await user.tab();
|
||||||
|
expect(screen.getByRole("button", { name: "Last action" })).toHaveFocus();
|
||||||
|
await user.tab();
|
||||||
|
expect(screen.getByRole("button", { name: "First action" })).toHaveFocus();
|
||||||
|
await user.keyboard("{Escape}");
|
||||||
|
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||||
|
await waitFor(() => expect(trigger).toHaveFocus());
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import { readFileSync } from "node:fs";
|
||||||
|
import { resolve } from "node:path";
|
||||||
|
|
||||||
|
import postcss from "postcss";
|
||||||
|
import tailwindcss from "tailwindcss";
|
||||||
|
import loadConfig from "tailwindcss/loadConfig";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
describe("sidebar touch hover isolation", () => {
|
||||||
|
it("gates ordinary and named-group hover CSS without gating keyboard focus", async () => {
|
||||||
|
const config = loadConfig(resolve(process.cwd(), "tailwind.config.js"));
|
||||||
|
const source = readFileSync(
|
||||||
|
resolve(process.cwd(), "src/components/ChatList.tsx"), "utf8",
|
||||||
|
);
|
||||||
|
const result = await postcss([tailwindcss({
|
||||||
|
...config,
|
||||||
|
content: [{ raw: source, extension: "tsx" }],
|
||||||
|
})]).process("@tailwind utilities;", { from: undefined });
|
||||||
|
const hoverSelectors: string[] = [];
|
||||||
|
const focusSelectors: string[] = [];
|
||||||
|
result.root.walkRules((rule) => {
|
||||||
|
if (rule.selector.includes(":hover")) {
|
||||||
|
hoverSelectors.push(rule.selector);
|
||||||
|
let parent = rule.parent;
|
||||||
|
let hoverMedia = false;
|
||||||
|
while (parent) {
|
||||||
|
if (parent.type === "atrule" && "name" in parent
|
||||||
|
&& parent.name === "media" && parent.params === "(hover: hover)") {
|
||||||
|
hoverMedia = true;
|
||||||
|
}
|
||||||
|
parent = parent.parent;
|
||||||
|
}
|
||||||
|
expect(hoverMedia, rule.selector).toBe(true);
|
||||||
|
}
|
||||||
|
if (rule.selector.includes(":focus-visible")) {
|
||||||
|
focusSelectors.push(rule.selector);
|
||||||
|
expect(rule.parent?.type).toBe("root");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(hoverSelectors.some((selector) => selector.includes("group:hover"))).toBe(true);
|
||||||
|
expect(hoverSelectors.some((selector) => selector.includes("group\\/tab:hover"))).toBe(true);
|
||||||
|
expect(hoverSelectors.some((selector) => selector.includes("group\\/pane:hover"))).toBe(true);
|
||||||
|
expect(focusSelectors.length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import animate from "tailwindcss-animate";
|
import animate from "tailwindcss-animate";
|
||||||
import typography from "@tailwindcss/typography";
|
import typography from "@tailwindcss/typography";
|
||||||
|
import plugin from "tailwindcss/plugin";
|
||||||
|
|
||||||
/** @type {import('tailwindcss').Config} */
|
/** @type {import('tailwindcss').Config} */
|
||||||
export default {
|
export default {
|
||||||
@@ -124,5 +125,13 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [animate, typography],
|
plugins: [
|
||||||
|
animate,
|
||||||
|
typography,
|
||||||
|
plugin(({ addVariant }) => {
|
||||||
|
// Revealing controls on emulated hover can consume the first Safari
|
||||||
|
// tap. Keep these sidebar hover effects on hover-capable pointers.
|
||||||
|
addVariant("media-hover", "@media (hover: hover)");
|
||||||
|
}),
|
||||||
|
],
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user