Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions __tests__/components/header/HeaderSearchModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ describe("HeaderSearchModal", () => {
jest.clearAllMocks();
});

it("associates the search input with an accessible label", () => {
setup();
expect(
screen.getByRole("textbox", {
name: "Search",
})
).toBeInTheDocument();
});

it("calls onClose when escape is pressed", () => {
const { onClose } = setup();
escapeCb();
Expand All @@ -88,7 +97,7 @@ describe("HeaderSearchModal", () => {

it("renders search results when query returns items", () => {
setup();
const input = screen.getByRole("textbox");
const input = screen.getByRole("textbox", { name: "Search" });
fireEvent.change(input, { target: { value: "abc" } });
expect(screen.getByTestId("item")).toBeInTheDocument();
});
Expand All @@ -101,7 +110,7 @@ describe("HeaderSearchModal", () => {

it("navigates on enter key", () => {
const { push } = setup();
const input = screen.getByRole("textbox");
const input = screen.getByRole("textbox", { name: "Search" });
fireEvent.change(input, { target: { value: "alice" } });
enterCb();
expect(push).toHaveBeenCalled();
Expand Down
4 changes: 4 additions & 0 deletions components/header/header-search/HeaderSearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,12 @@ export default function HeaderSearchModal({
clipRule="evenodd"
/>
</svg>
<label className="tw-sr-only" htmlFor="header-search-input">
Search
</label>
<input
ref={inputRef}
id="header-search-input"
type="text"
required
autoComplete="off"
Expand Down