Skip to content

Commit 7d3cf36

Browse files
committed
Revert Trix.config.editor changes
1 parent 5806006 commit 7d3cf36

File tree

8 files changed

+25
-55
lines changed

8 files changed

+25
-55
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ on:
88

99
jobs:
1010
build:
11-
name: "Browser tests (Trix.config.editor.formAssociated = ${{ matrix.formAssociated }})"
12-
strategy:
13-
matrix:
14-
formAssociated: [true, false]
15-
env:
16-
FORM_ASSOCIATED: "${{ matrix.formAssociated }}"
11+
name: Browser tests
1712
runs-on: ubuntu-latest
1813
steps:
1914
- uses: actions/checkout@v3

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ Clicking the quote button toggles whether the block should be rendered with `<bl
9090

9191
## Integrating with Element Internals
9292

93-
Trix will integrate `<trix-editor>` elements with forms depending on the browser's support for [Element Internals](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals). By default, Trix will enable support for `ElementInternals` when the feature is enabled in the browser. If there is a need to disable support for `ElementInternals`, set `Trix.config.editor.formAssociated = false`:
93+
Trix will integrate `<trix-editor>` elements with forms depending on the browser's support for [Element Internals](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals). If there is a need to disable support for `ElementInternals`, set `Trix.elements.TrixEditorElement.formAssociated = false`:
9494

9595
```js
9696
import Trix from "trix"
9797

98-
Trix.config.editor.formAssociated = false
98+
Trix.elements.TrixEditorElement.formAssociated = false
9999
```
100100

101101
## Invoking Internal Trix Actions

karma.conf.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const config = {
33
frameworks: [ "qunit" ],
44
files: [
55
{ pattern: "dist/test.js", watched: false },
6-
{ pattern: "src/test/test_helpers/fixtures/*.png", watched: false, included: false, served: true }
6+
{ pattern: "src/test_helpers/fixtures/*.png", watched: false, included: false, served: true }
77
],
88
proxies: {
99
"/test_helpers/fixtures/": "/base/src/test_helpers/fixtures/"
@@ -29,14 +29,6 @@ const config = {
2929

3030
/* eslint camelcase: "off", */
3131

32-
if (process.env.FORM_ASSOCIATED === "false") {
33-
config.files.push({
34-
pattern: "src/test/test_helpers/fixtures/form_associated_false.js",
35-
watched: false,
36-
included: true
37-
})
38-
}
39-
4032
if (process.env.SAUCE_ACCESS_KEY) {
4133
config.customLaunchers = {
4234
sl_chrome_latest: {

src/test/system/custom_element_test.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as config from "trix/config"
21
import { rangesAreEqual } from "trix/core/helpers"
2+
import TrixEditorElement from "trix/elements/trix_editor_element"
33

44
import {
55
TEST_IMAGE_URL,
@@ -560,7 +560,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
560560
assert.equal("trix-editor", element.type)
561561
})
562562

563-
testIfFormAssociated("adds [disabled] attribute based on .disabled property", () => {
563+
testIf(TrixEditorElement.formAssociated, "adds [disabled] attribute based on .disabled property", () => {
564564
const editor = document.getElementById("editor-with-ancestor-form")
565565

566566
editor.disabled = true
@@ -572,7 +572,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
572572
assert.equal(editor.hasAttribute("disabled"), false, "removes [disabled] attribute")
573573
})
574574

575-
testIfFormAssociated("removes [contenteditable] and disables input when editor element has [disabled]", () => {
575+
testIf(TrixEditorElement.formAssociated, "removes [contenteditable] and disables input when editor element has [disabled]", () => {
576576
const editor = document.getElementById("editor-with-no-form")
577577

578578
editor.setAttribute("disabled", "")
@@ -590,7 +590,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
590590
assert.equal(editor.hasAttribute("contenteditable"), true, "adds [contenteditable] attribute")
591591
})
592592

593-
testIfFormAssociated("removes [contenteditable] and disables input when editor element is :disabled", () => {
593+
testIf(TrixEditorElement.formAssociated, "removes [contenteditable] and disables input when editor element is :disabled", () => {
594594
const editor = document.getElementById("editor-within-fieldset")
595595
const fieldset = document.getElementById("fieldset")
596596

@@ -611,7 +611,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
611611
assert.equal(editor.hasAttribute("contenteditable"), true, "adds [contenteditable] attribute")
612612
})
613613

614-
testIfFormAssociated("does not receive focus when :disabled", () => {
614+
testIf(TrixEditorElement.formAssociated, "does not receive focus when :disabled", () => {
615615
const activeEditor = document.getElementById("editor-with-input-form")
616616
const editor = document.getElementById("editor-within-fieldset")
617617

@@ -622,7 +622,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
622622
assert.equal(activeEditor, document.activeElement, "disabled editor does not receive focus")
623623
})
624624

625-
testIfFormAssociated("disabled editor does not encode its value when the form is submitted", () => {
625+
testIf(TrixEditorElement.formAssociated, "disabled editor does not encode its value when the form is submitted", () => {
626626
const editor = document.getElementById("editor-with-ancestor-form")
627627
const form = editor.form
628628

@@ -632,7 +632,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
632632
assert.deepEqual({}, Object.fromEntries(new FormData(form).entries()), "does not write to FormData")
633633
})
634634

635-
testIfFormAssociated("validates with [required] attribute as invalid", () => {
635+
testIf(TrixEditorElement.formAssociated, "validates with [required] attribute as invalid", () => {
636636
const editor = document.getElementById("editor-with-ancestor-form")
637637
const form = editor.form
638638
let invalidEvent, submitEvent = null
@@ -651,7 +651,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
651651
assert.equal(submitEvent, null, "does not dispatch a 'submit' event")
652652
})
653653

654-
testIfFormAssociated("does not validate with [disabled] attribute", () => {
654+
testIf(TrixEditorElement.formAssociated, "does not validate with [disabled] attribute", () => {
655655
const editor = document.getElementById("editor-with-ancestor-form")
656656
let invalidEvent = null
657657

@@ -663,7 +663,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
663663
assert.equal(invalidEvent, null, "does not dispatch an 'invalid' event")
664664
})
665665

666-
testIfFormAssociated("re-validates when the value changes", async () => {
666+
testIf(TrixEditorElement.formAssociated, "re-validates when the value changes", async () => {
667667
const editor = document.getElementById("editor-with-ancestor-form")
668668
editor.required = true
669669
editor.focus()
@@ -677,7 +677,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
677677
assert.equal(editor.validationMessage, "", "clears the validationMessage")
678678
})
679679

680-
testIfFormAssociated("accepts a customError validation message", () => {
680+
testIf(TrixEditorElement.formAssociated, "accepts a customError validation message", () => {
681681
const editor = document.getElementById("editor-with-ancestor-form")
682682

683683
editor.setCustomValidity("A custom validation message")
@@ -687,13 +687,3 @@ testGroup("form property references its <form>", { template: "editors_with_forms
687687
assert.equal(editor.validationMessage, "A custom validation message")
688688
})
689689
})
690-
691-
function testIfFormAssociated(name, callback) {
692-
test(name, async () => {
693-
if (config.editor.formAssociated) {
694-
await callback()
695-
} else {
696-
assert.equal(config.editor.formAssociated, false, "skipping test that requires ElementInternals")
697-
}
698-
})
699-
}

src/test/test_helpers/fixtures/form_associated_false.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/trix/config/editor.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/trix/config/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export { default as attachments } from "./attachments"
22
export { default as blockAttributes } from "./block_attributes"
33
export { default as browser } from "./browser"
44
export { default as css } from "./css"
5-
export { default as editor } from "./editor"
65
export { default as fileSize } from "./file_size_formatting"
76
export { default as input } from "./input"
87
export { default as keyNames } from "./key_names"

src/trix/elements/trix_editor_element.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ installDefaultCSSForTagName("trix-editor", `\
161161
}`)
162162

163163
export default class TrixEditorElement extends HTMLElement {
164-
static get formAssociated() {
165-
return config.editor.formAssociated
166-
}
164+
static formAssociated = "ElementInternals" in window
167165

168166
#customValidationMessage
169167
#internals
@@ -261,7 +259,7 @@ export default class TrixEditorElement extends HTMLElement {
261259
if (this.#internals) {
262260
return this.inputElement.disabled
263261
} else {
264-
console.warn("Trix is not configured to support the [disabled] attribute. Set Trix.config.editor.formAssociated = true")
262+
console.warn("This browser does not support the [disabled] attribute for trix-editor elements.")
265263

266264
return false
267265
}
@@ -271,15 +269,15 @@ export default class TrixEditorElement extends HTMLElement {
271269
if (this.#internals) {
272270
this.toggleAttribute("disabled", value)
273271
} else {
274-
console.warn("Trix is not configured to support the [disabled] attribute. Set Trix.config.editor.formAssociated = true")
272+
console.warn("This browser does not support the [disabled] attribute for trix-editor elements.")
275273
}
276274
}
277275

278276
get required() {
279277
if (this.#internals) {
280278
return this.hasAttribute("required")
281279
} else {
282-
console.warn("Trix is not configured to support the [required] attribute. Set Trix.config.editor.formAssociated = true")
280+
console.warn("This browser does not support the [required] attribute for trix-editor elements.")
283281

284282
return false
285283
}
@@ -290,15 +288,15 @@ export default class TrixEditorElement extends HTMLElement {
290288
this.toggleAttribute("required", value)
291289
this.#synchronizeValidation()
292290
} else {
293-
console.warn("Trix is not configured to support the [required] attribute. Set Trix.config.editor.formAssociated = true")
291+
console.warn("This browser does not support the [required] attribute for trix-editor elements.")
294292
}
295293
}
296294

297295
get validity() {
298296
if (this.#internals) {
299297
return this.#internals.validity
300298
} else {
301-
console.warn("Trix is not configured to support the validity property. Set Trix.config.editor.formAssociated = true")
299+
console.warn("This browser does not support the validity property for trix-editor elements.")
302300
return null
303301
}
304302
}
@@ -307,7 +305,7 @@ export default class TrixEditorElement extends HTMLElement {
307305
if (this.#internals) {
308306
return this.#internals.validationMessage
309307
} else {
310-
console.warn("Trix is not configured to support the validationMessage property. Set Trix.config.editor.formAssociated = true")
308+
console.warn("This browser does not support the validationMessage property for trix-editor elements.")
311309

312310
return ""
313311
}
@@ -317,7 +315,7 @@ export default class TrixEditorElement extends HTMLElement {
317315
if (this.#internals) {
318316
return this.#internals.willValidate
319317
} else {
320-
console.warn("Trix is not configured to support the willValidate property. Set Trix.config.editor.formAssociated = true")
318+
console.warn("This browser does not support the willValidate property for trix-editor elements.")
321319

322320
return false
323321
}
@@ -425,7 +423,7 @@ export default class TrixEditorElement extends HTMLElement {
425423
if (this.#internals) {
426424
return this.#internals.checkValidity()
427425
} else {
428-
console.warn("Trix is not configured to support checkValidity(). Set Trix.config.editor.formAssociated = true")
426+
console.warn("This browser does not support checkValidity() for trix-editor elements.")
429427

430428
return true
431429
}
@@ -435,7 +433,7 @@ export default class TrixEditorElement extends HTMLElement {
435433
if (this.#internals) {
436434
return this.#internals.reportValidity()
437435
} else {
438-
console.warn("Trix is not configured to support reportValidity(). Set Trix.config.editor.formAssociated = true")
436+
console.warn("This browser does not support reportValidity() for trix-editor elements.")
439437

440438
return true
441439
}
@@ -447,7 +445,7 @@ export default class TrixEditorElement extends HTMLElement {
447445

448446
this.#synchronizeValidation()
449447
} else {
450-
console.warn("Trix is not configured to support setCustomValidity(validationMessage). Set Trix.config.editor.formAssociated = true")
448+
console.warn("This browser does not support setCustomValidity(validationMessage) for trix-editor elements.")
451449
}
452450
}
453451

0 commit comments

Comments
 (0)