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

editableFocus.browser.test.ts

23 lines794 Bytes

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