Stop dark text fields from looking pre-selected when they auto-focus.

This commit is contained in:
adilallo committed 2026-11-23 14:30:43 -07:00
1 parent 36112f95d3
commit 6aa06126b5
6 files changed
+111 -22

No files matched your search

+40 -1
View File
@@ -1,10 +1,17 @@
import React from "react";
import { describe, it, expect } from "vitest";
import { describe, it, expect, vi } from "vitest";
import { fireEvent } from "@testing-library/react";
import { renderWithProviders as render } from "../utils/test-utils";
import "@testing-library/jest-dom/vitest";
import TextInput from "../../app/components/controls/TextInput";
import { componentTestSuite } from "../utils/componentTestSuite";
function keyboardFocusRing(container: HTMLElement) {
return [...container.querySelectorAll('[aria-hidden="true"]')].find((el) =>
el.className.includes("shadow-[var(--shadow-focus-default)]"),
);
}
type TextInputProps = React.ComponentProps<typeof TextInput>;
componentTestSuite<TextInputProps>({
@@ -82,6 +89,38 @@ describe("TextInput (size tests)", () => {
expect(input).toHaveAttribute("form", "create-flow-community-save");
});
it("does not draw the keyboard ring on programmatic focus", () => {
const { container } = render(<TextInput label="Email address" />);
const input = container.querySelector("input");
expect(input).not.toBeNull();
fireEvent.focus(input!);
expect(keyboardFocusRing(container)).toBeUndefined();
expect(input).toHaveClass("appearance-none");
});
it("draws the keyboard ring when :focus-visible", () => {
const { container } = render(<TextInput label="Email address" />);
const input = container.querySelector("input");
expect(input).not.toBeNull();
vi.spyOn(input!, "matches").mockImplementation(
(selector: string) => selector === ":focus-visible",
);
fireEvent.focus(input!);
expect(keyboardFocusRing(container)?.className).toContain(
"shadow-[var(--shadow-focus-default)]",
);
});
it("uses the active border on pointer focus, not the keyboard ring", () => {
const { container } = render(<TextInput label="Email address" />);
const input = container.querySelector("input");
expect(input).not.toBeNull();
fireEvent.mouseDown(input!);
fireEvent.focus(input!);
expect(keyboardFocusRing(container)).toBeUndefined();
expect(input).toHaveClass("border-2");
});
it("keeps read-only values at full contrast", () => {
const { container } = render(
<TextInput