Skip to content

Commit

Permalink
Extract LegacyDelegate and ElementInternalsDelegate
Browse files Browse the repository at this point in the history
Delegate implementation-specific methods and properties to the
appropriate delegate. Set the delegate based on the
`TrixEditorElement.formAssociated` property.
  • Loading branch information
seanpdoyle committed Oct 11, 2024
1 parent 7d3cf36 commit 1cfa094
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 181 deletions.
13 changes: 7 additions & 6 deletions src/test/system/accessibility_test.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
import { assert, test, testGroup, triggerEvent } from "test/test_helper"
import { assert, skipIf, test, testGroup, triggerEvent } from "test/test_helper"
import TrixEditorElement from "trix/elements/trix_editor_element"

testGroup("Accessibility attributes", { template: "editor_default_aria_label" }, () => {
test("sets the role to textbox", () => {
const editor = document.getElementById("editor-without-labels")
assert.equal(editor.getAttribute("role"), "textbox")
})

test("does not set aria-label when the element has no <label> elements", () => {
skipIf(TrixEditorElement.formAssociated, "does not set aria-label when the element has no <label> elements", () => {
const editor = document.getElementById("editor-without-labels")
assert.equal(editor.hasAttribute("aria-label"), false)
})

test("does not override aria-label when the element declares it", () => {
skipIf(TrixEditorElement.formAssociated, "does not override aria-label when the element declares it", () => {
const editor = document.getElementById("editor-with-aria-label")
assert.equal(editor.getAttribute("aria-label"), "ARIA Label text")
})

test("does not set aria-label when the element declares aria-labelledby", () => {
skipIf(TrixEditorElement.formAssociated, "does not set aria-label when the element declares aria-labelledby", () => {
const editor = document.getElementById("editor-with-aria-labelledby")
assert.equal(editor.hasAttribute("aria-label"), false)
assert.equal(editor.getAttribute("aria-labelledby"), "aria-labelledby-id")
})

test("assigns aria-label to the text of the element's <label> elements", () => {
skipIf(TrixEditorElement.formAssociated, "assigns aria-label to the text of the element's <label> elements", () => {
const editor = document.getElementById("editor-with-labels")
assert.equal(editor.getAttribute("aria-label"), "Label 1 Label 2 Label 3")
})

test("updates the aria-label on focus", () => {
skipIf(TrixEditorElement.formAssociated, "updates the aria-label on focus", () => {
const editor = document.getElementById("editor-with-modified-label")
const label = document.getElementById("modified-label")

Expand Down
4 changes: 4 additions & 0 deletions src/test/test_helpers/test_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export const testGroup = function (name, options, callback) {
}
}

export const skipIf = function (condition, ...args) {
testIf(!condition, ...args)
}

export const testIf = function (condition, ...args) {
if (condition) {
test(...Array.from(args || []))
Expand Down
Loading

0 comments on commit 1cfa094

Please sign in to comment.