Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/a11y-link-text-label.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stackoverflow/stacks-editor": patch
---

Associate the visible link text label with its form input.
2 changes: 1 addition & 1 deletion src/rich-text/plugins/link-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class LinkEditor extends PluginInterfaceView<
<label for="link-editor-text-input-${randomId}" class="s-label mb4">${_t(
"link_editor.text_label"
)}</label>
<input id="link-text-href-input-${randomId}" class="s-input js-link-editor-text" type="text" name="text" />
<input id="link-editor-text-input-${randomId}" class="s-input js-link-editor-text" type="text" name="text" />
</div>

<div class="flex--item">
Expand Down
23 changes: 23 additions & 0 deletions test/rich-text/plugins/link-editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@ describe("link-editor", () => {
expect(updatedUploadContainer.parentElement).toBeTruthy();
});

it("should associate each visible label with its input", () => {
showLinkEditor(view.editorView);
editor.update(view.editorView);

const container = getViewContainer(editor);
const labels =
container.querySelectorAll<HTMLLabelElement>("label");
const inputs = [
container.querySelector<HTMLInputElement>(
".js-link-editor-href"
),
container.querySelector<HTMLInputElement>(
".js-link-editor-text"
),
];

expect(labels).toHaveLength(2);
labels.forEach((label, index) => {
expect(inputs[index]).toBeInstanceOf(HTMLInputElement);
expect(label.htmlFor).toBe(inputs[index]?.id);
});
});

it("should focus first input when showing image uploader", () => {
// we need to add our DOM to the doc's body in order to make jsdom's "focus" handling work
// see https://github.com/jsdom/jsdom/issues/2586#issuecomment-742593116
Expand Down
Loading