- Notifications
You must be signed in to change notification settings - Fork 0
fix(a11y): give the view switcher and the exit mode real semantics#17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
devRMA
merged 1 commit into
fix/hero-panel-value-overflow
from
fix/a11y-tabs-and-radio-groupAug 2, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { render, screen } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { CalculatorViews, CalculatorViewsFromUrl, toCalculatorView } from "@/components/organisms/calculator-views"; | ||
| import { safeGAEvent } from "@/lib/analytics"; | ||
| vi.mock("@/lib/analytics", () => ({ | ||
| safeGAEvent: vi.fn(), | ||
| })); | ||
| vi.mock("@/components/organisms/work-calculator", () => ({ | ||
| WorkCalculator: () => <p>Painel da jornada</p>, | ||
| })); | ||
| vi.mock("@/components/organisms/salary-calculator", () => ({ | ||
| SalaryCalculator: () => <p>Painel do custo da hora</p>, | ||
| })); | ||
| const searchParams = { current: new URLSearchParams() }; | ||
| vi.mock("next/navigation", () => ({ | ||
| useSearchParams: () => searchParams.current, | ||
| })); | ||
| describe("toCalculatorView", () => { | ||
| it("only accepts the salary view, falling back to the journey", () => { | ||
| expect(toCalculatorView("salary")).toBe("salary"); | ||
| expect(toCalculatorView("work")).toBe("work"); | ||
| expect(toCalculatorView("anything-else")).toBe("work"); | ||
| expect(toCalculatorView(null)).toBe("work"); | ||
| }); | ||
| }); | ||
| describe("CalculatorViews", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| searchParams.current = new URLSearchParams(); | ||
| }); | ||
| it("marks the active tab and links both views by URL", () => { | ||
| render(<CalculatorViews activeView="salary" />); | ||
| expect(screen.getByRole("link", { name: "Jornada" })).toHaveAttribute("href", "/?view=work"); | ||
| expect(screen.getByRole("link", { name: "Custo da Hora" })).toHaveAttribute("href", "/?view=salary"); | ||
| expect(screen.getByRole("link", { name: "Custo da Hora" })).toHaveAttribute("aria-current", "page"); | ||
| expect(screen.getByRole("link", { name: "Jornada" })).not.toHaveAttribute("aria-current"); | ||
| }); | ||
| it("renders the panel matching the active view", async () => { | ||
| const { rerender } = render(<CalculatorViews activeView="work" />); | ||
| expect(screen.getByText("Painel da jornada")).toBeInTheDocument(); | ||
| rerender(<CalculatorViews activeView="salary" />); | ||
| expect(await screen.findByText("Painel do custo da hora")).toBeInTheDocument(); | ||
| }); | ||
| it("tracks the tab the visitor moves to", async () => { | ||
| const user = userEvent.setup(); | ||
| render(<CalculatorViews activeView="work" />); | ||
| await user.click(screen.getByRole("link", { name: "Custo da Hora" })); | ||
| expect(safeGAEvent).toHaveBeenCalledWith("switch_tab", { tab: "salary" }); | ||
| }); | ||
| it("reads the active view from the query string", () => { | ||
| searchParams.current = new URLSearchParams("view=salary"); | ||
| render(<CalculatorViewsFromUrl />); | ||
| expect(screen.getByText("Painel do custo da hora")).toBeInTheDocument(); | ||
| }); | ||
| it("falls back to the journey when the query string has no view", () => { | ||
| render(<CalculatorViewsFromUrl />); | ||
| expect(screen.getByText("Painel da jornada")).toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| "use client"; | ||
| import { Clock, DollarSign } from "lucide-react"; | ||
| import { AnimatePresence, motion } from "motion/react"; | ||
| import Link from "next/link"; | ||
| import { useSearchParams } from "next/navigation"; | ||
| import { buttonClasses } from "@/components/atoms/button"; | ||
| import { SalaryCalculator } from "@/components/organisms/salary-calculator"; | ||
| import { WorkCalculator } from "@/components/organisms/work-calculator"; | ||
| import { safeGAEvent } from "@/lib/analytics"; | ||
| export type CalculatorView = "work" | "salary"; | ||
| const DEFAULT_VIEW: CalculatorView = "work"; | ||
| const VIEW_TABS: readonly { view: CalculatorView; label: string; icon: typeof Clock }[] = [ | ||
| { view: "work", label: "Jornada", icon: Clock }, | ||
| { view: "salary", label: "Custo da Hora", icon: DollarSign }, | ||
| ]; | ||
| const PANEL_TRANSITION = { | ||
| initial: { opacity: 0, y: 20, scale: 0.98 }, | ||
| animate: { opacity: 1, y: 0, scale: 1 }, | ||
| exit: { opacity: 0, y: -20, scale: 0.98 }, | ||
| transition: { duration: 0.4, ease: [0.23, 1, 0.32, 1] }, | ||
| } as const; | ||
| export function toCalculatorView(rawView: string | null): CalculatorView { | ||
| return rawView === "salary" ? "salary" : DEFAULT_VIEW; | ||
| } | ||
| export function CalculatorViews({ activeView }: { activeView: CalculatorView }) { | ||
| return ( | ||
| <> | ||
| <nav aria-label="Calculadoras" className="fixed bottom-8 left-1/2 -translate-x-1/2 z-50"> | ||
| <ul className="bg-white/80 dark:bg-neutral-900/80 backdrop-blur-xl border border-neutral-200 dark:border-neutral-800 p-1.5 rounded-2xl shadow-2xl flex items-center gap-1"> | ||
| {VIEW_TABS.map(({ view, label, icon: Icon }) => ( | ||
| <li key={view}> | ||
| <Link | ||
| href={`/?view=${view}`} | ||
| scroll={false} | ||
| aria-current={activeView === view ? "page" : undefined} | ||
| onClick={() => safeGAEvent("switch_tab", { tab: view })} | ||
| className={buttonClasses(activeView === view ? "default" : "ghost", "default", "gap-2")} | ||
| > | ||
| <Icon className="w-4 h-4" aria-hidden="true" /> | ||
| <span>{label}</span> | ||
| </Link> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </nav> | ||
| <div | ||
| id="main-content" | ||
| tabIndex={-1} | ||
| className="pt-32 pb-32 px-4 sm:px-6 lg:px-8 outline-none focus-visible:ring-2 focus-visible:ring-indigo-500" | ||
devRMA marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| > | ||
| <AnimatePresence mode="wait"> | ||
| <motion.div key={activeView} {...PANEL_TRANSITION}> | ||
| {activeView === "work" ? <WorkCalculator /> : <SalaryCalculator />} | ||
| </motion.div> | ||
| </AnimatePresence> | ||
| </div> | ||
| </> | ||
| ); | ||
| } | ||
| export function CalculatorViewsFromUrl() { | ||
| return <CalculatorViews activeView={toCalculatorView(useSearchParams().get("view"))} />; | ||
| } | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.