Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

editableFocus.test.ts

25 lines824 Bytes

1// @vitest-environment jsdom
2​
3import { afterEach, describe, expect, it } from "vite-plus/test";
4​
5import { isEditableFocused } from "./editableFocus";
6​
7afterEach(() => {
8 document.body.replaceChildren();
9});
10​
11describe("isEditableFocused", () => {
12 it("sees a text field focused inside an open shadow root", () => {
13 // A key event from a shadow input is retargeted to its host, so the host is
14 // what page-level shortcut handlers receive as the event target.
15 const host = document.createElement("div");
16 const input = document.createElement("input");
17 host.attachShadow({ mode: "open" }).append(input);
18 document.body.append(host);
19​
20 expect(isEditableFocused(host)).toBe(false);
21 input.focus();
22 expect(isEditableFocused(host)).toBe(true);
23 expect(isEditableFocused()).toBe(true);
24 });
25});