|
| 1 | +import { render } from "@testing-library/react"; |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | + |
| 4 | +import { navigationMenuTriggerStyle } from "./navigation-menu"; |
| 5 | +import { Select, SelectTrigger, SelectValue } from "./select"; |
| 6 | + |
| 7 | +// Regression for #8304: SelectTrigger, the Dialog/Sheet close buttons, and NavigationMenuTrigger must |
| 8 | +// apply their focus ring/highlight via `focus-visible:` (keyboard/programmatic focus only), matching |
| 9 | +// every other interactive primitive in @loopover/ui-kit — never on plain `focus:`, which also fires on |
| 10 | +// mouse-click focus and leaves a lingering ring/highlight. `focus:outline-none` is intentionally kept |
| 11 | +// (clearing the native outline on any focus is correct and shared by every primitive). |
| 12 | +describe("focus-visible convention (#8304)", () => { |
| 13 | + it("navigationMenuTriggerStyle highlights on focus-visible, never a bare focus:bg-accent", () => { |
| 14 | + const classes = navigationMenuTriggerStyle(); |
| 15 | + expect(classes).toContain("focus-visible:bg-accent"); |
| 16 | + expect(classes).toContain("focus-visible:text-accent-foreground"); |
| 17 | + // No bare focus:bg-accent / focus:text-accent-foreground (the data-[state=open]:focus:bg-accent |
| 18 | + // compound is a separate, intentional open-state rule and is allowed). |
| 19 | + expect(classes).not.toMatch(/(?<!:)\bfocus:bg-accent\b/); |
| 20 | + expect(classes).not.toMatch(/(?<!:)\bfocus:text-accent-foreground\b/); |
| 21 | + // The native-outline clear stays on plain focus:. |
| 22 | + expect(classes).toContain("focus:outline-none"); |
| 23 | + }); |
| 24 | + |
| 25 | + it("SelectTrigger rings on focus-visible, never a bare focus:ring", () => { |
| 26 | + const { getByRole } = render( |
| 27 | + <Select> |
| 28 | + <SelectTrigger aria-label="pick"> |
| 29 | + <SelectValue placeholder="pick" /> |
| 30 | + </SelectTrigger> |
| 31 | + </Select>, |
| 32 | + ); |
| 33 | + const trigger = getByRole("combobox"); |
| 34 | + expect(trigger.className).toContain("focus-visible:ring-1"); |
| 35 | + expect(trigger.className).toContain("focus-visible:ring-ring"); |
| 36 | + expect(trigger.className).not.toMatch(/(?<!-)\bfocus:ring/); |
| 37 | + expect(trigger.className).toContain("focus:outline-none"); |
| 38 | + }); |
| 39 | +}); |
0 commit comments