From c1a03bfcb1679bf4319db554d9744a858eb4501b Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sat, 21 Nov 2026 08:04:06 -0600 Subject: [PATCH] fix(id-web): associate image alt text label --- pkgs/id/web/src/image-node-view.test.ts | 13 +++++++++++++ pkgs/id/web/src/image-node-view.ts | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkgs/id/web/src/image-node-view.test.ts b/pkgs/id/web/src/image-node-view.test.ts index e7274d62a5..a686713f02 100644 --- a/pkgs/id/web/src/image-node-view.test.ts +++ b/pkgs/id/web/src/image-node-view.test.ts @@ -168,6 +168,19 @@ describe("resize clamps", () => { // ── Committed attrs on mouse-up ──────────────────────────────────── +describe("image alt-text editor accessibility", () => { + it("associates the visible Alt text label with its input", () => { + const { nv } = setup(); + nv.dom.dispatchEvent(new MouseEvent("click", { bubbles: true })); + + const label = nv.dom.querySelector(".pm-image-popover-label"); + const input = nv.dom.querySelector(".pm-image-popover-input"); + expect(label).not.toBeNull(); + expect(input).not.toBeNull(); + expect(label?.control).toBe(input); + }); +}); + describe("committed attrs on mouse-up", () => { it("nw outward drag commits the GROWN width/height to the node attrs", () => { const { view, nv, img } = setup(); diff --git a/pkgs/id/web/src/image-node-view.ts b/pkgs/id/web/src/image-node-view.ts index 45fe6e895f..3704aa149f 100644 --- a/pkgs/id/web/src/image-node-view.ts +++ b/pkgs/id/web/src/image-node-view.ts @@ -118,6 +118,9 @@ export class ImageNodeView implements NodeView { input.className = "pm-image-popover-input"; input.value = this.node.attrs.alt || ""; input.placeholder = "Describe this image…"; + // Nesting the input in its visible label gives assistive technology a + // programmatic name without a page-global id that could be duplicated. + label.appendChild(input); // Commit on Enter or blur const commit = () => { @@ -147,7 +150,6 @@ export class ImageNodeView implements NodeView { sizeInfo.textContent = `${w} × ${h}`; popover.appendChild(label); - popover.appendChild(input); popover.appendChild(sizeInfo); this.dom.appendChild(popover);