| 1 | // @vitest-environment jsdom |
| 2 | |
| 3 | import { afterEach, describe, expect, it } from "vite-plus/test"; |
| 4 | |
| 5 | import { isEditableFocused } from "./editableFocus"; |
| 6 | |
| 7 | afterEach(() => { |
| 8 | document.body.replaceChildren(); |
| 9 | }); |
| 10 | |
| 11 | describe("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 | }); |