Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
fix(ui): preserve carousel keyboard and accessibility semantics (#728)
Kevin Rajanbee227141635
diff --git a/app/src/components/ui/carousel.tsx b/app/src/components/ui/carousel.tsxindex a795131d..5af04162 100644--- a/app/src/components/ui/carousel.tsx+++ b/app/src/components/ui/carousel.tsx@@ -43,6 +43,26 @@ function useCarousel() {return context;}+export function carouselKeyboardAction(+ orientation: "horizontal" | "vertical",+ key: string,+ target: EventTarget | null,+): "prev" | "next" | null {+ if (+ target instanceof HTMLElement &&+ (target.matches("input, textarea, select") || target.isContentEditable)+ )+ return null;+ if (orientation === "horizontal") {+ if (key === "ArrowLeft") return "prev";+ if (key === "ArrowRight") return "next";+ } else {+ if (key === "ArrowUp") return "prev";+ if (key === "ArrowDown") return "next";+ }+ return null;+}+function Carousel({orientation = "horizontal",opts,@@ -78,15 +98,17 @@ function Carousel({const handleKeyDown = React.useCallback((event: React.KeyboardEvent<HTMLDivElement>) => {- if (event.key === "ArrowLeft") {- event.preventDefault();- scrollPrev();- } else if (event.key === "ArrowRight") {- event.preventDefault();- scrollNext();- }+ const action = carouselKeyboardAction(+ orientation,+ event.key,+ event.target,+ );+ if (!action) return;+ event.preventDefault();+ if (action === "prev") scrollPrev();+ else scrollNext();},- [scrollPrev, scrollNext],+ [orientation, scrollPrev, scrollNext],);React.useEffect(() => {@@ -101,7 +123,8 @@ function Carousel({api.on("select", onSelect);return () => {- api?.off("select", onSelect);+ api.off("reInit", onSelect);+ api.off("select", onSelect);};}, [api, onSelect]);diff --git a/app/src/routes/_authed/_app/index.tsx b/app/src/routes/_authed/_app/index.tsxindex 792a9537..0c3ef384 100644--- a/app/src/routes/_authed/_app/index.tsx+++ b/app/src/routes/_authed/_app/index.tsx@@ -154,9 +154,14 @@ function RouteComponent() {// Wins over `failed`: a failed background refetch does not clear TanStack Query's// cached `data`, so a stale carousel here beats an error card claiming there is// nothing to explore, which would be false while this list is still populated.- <Carousel opts={{ align: "start" }}>+ <Carousel+ opts={{ align: "start" }}+ aria-labelledby="explore-agents-heading"+ ><div className="flex flex-row items-center justify-between gap-4">- <h2 className="font-bold text-lg">Explore agents</h2>+ <h2 id="explore-agents-heading" className="font-bold text-lg">+ Explore agents+ </h2>{/** `static` undoes the primitive's own absolute placement, which parks these either* side of the row and off the edge of a prose-width column. They belong on thediff --git a/app/tests/carousel-keyboard.test.ts b/app/tests/carousel-keyboard.test.tsnew file mode 100644index 00000000..e3e1745c--- /dev/null+++ b/app/tests/carousel-keyboard.test.ts@@ -0,0 +1,41 @@+import { afterAll, beforeAll, expect, test } from "bun:test";+import { GlobalRegistrator } from "@happy-dom/global-registrator";+import { carouselKeyboardAction } from "../src/components/ui/carousel";++beforeAll(() => GlobalRegistrator.register());+afterAll(() => GlobalRegistrator.unregister());++test("horizontal carousels use left and right arrows", () => {+ const target = document.createElement("div");+ expect(carouselKeyboardAction("horizontal", "ArrowLeft", target)).toBe(+ "prev",+ );+ expect(carouselKeyboardAction("horizontal", "ArrowRight", target)).toBe(+ "next",+ );+ expect(carouselKeyboardAction("horizontal", "ArrowUp", target)).toBeNull();+});++test("vertical carousels use up and down arrows", () => {+ const target = document.createElement("div");+ expect(carouselKeyboardAction("vertical", "ArrowUp", target)).toBe("prev");+ expect(carouselKeyboardAction("vertical", "ArrowDown", target)).toBe("next");+ expect(carouselKeyboardAction("vertical", "ArrowLeft", target)).toBeNull();+});++test("editable descendants keep their native arrow keys", () => {+ for (const tag of ["input", "textarea", "select"] as const) {+ const target = document.createElement(tag);+ expect(+ carouselKeyboardAction("horizontal", "ArrowLeft", target),+ ).toBeNull();+ expect(+ carouselKeyboardAction("horizontal", "ArrowRight", target),+ ).toBeNull();+ }+ const editable = document.createElement("div");+ editable.contentEditable = "true";+ expect(+ carouselKeyboardAction("horizontal", "ArrowLeft", editable),+ ).toBeNull();+});