Skip to content

Commit

Permalink
Revert Trix.config.editor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
seanpdoyle committed Oct 6, 2024
1 parent 5806006 commit 0e686ba
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 38 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ on:

jobs:
build:
name: "Browser tests (Trix.config.editor.formAssociated = ${{ matrix.formAssociated }})"
strategy:
matrix:
formAssociated: [true, false]
env:
FORM_ASSOCIATED: "${{ matrix.formAssociated }}"
name: Browser tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ Clicking the quote button toggles whether the block should be rendered with `<bl

## Integrating with Element Internals

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`:
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`:

```js
import Trix from "trix"

Trix.config.editor.formAssociated = false
Trix.elements.TrixEditorElement.formAssociated = false
```

## Invoking Internal Trix Actions
Expand Down
10 changes: 1 addition & 9 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const config = {
frameworks: [ "qunit" ],
files: [
{ pattern: "dist/test.js", watched: false },
{ pattern: "src/test/test_helpers/fixtures/*.png", watched: false, included: false, served: true }
{ pattern: "src/test_helpers/fixtures/*.png", watched: false, included: false, served: true }
],
proxies: {
"/test_helpers/fixtures/": "/base/src/test_helpers/fixtures/"
Expand All @@ -29,14 +29,6 @@ const config = {

/* eslint camelcase: "off", */

if (process.env.FORM_ASSOCIATED === "false") {
config.files.push({
pattern: "src/test/test_helpers/fixtures/form_associated_false.js",
watched: false,
included: true
})
}

if (process.env.SAUCE_ACCESS_KEY) {
config.customLaunchers = {
sl_chrome_latest: {
Expand Down
6 changes: 3 additions & 3 deletions src/test/system/custom_element_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as config from "trix/config"
import { rangesAreEqual } from "trix/core/helpers"
import TrixEditorElement from "trix/elements/trix_editor_element"

import {
TEST_IMAGE_URL,
Expand Down Expand Up @@ -690,10 +690,10 @@ testGroup("form property references its <form>", { template: "editors_with_forms

function testIfFormAssociated(name, callback) {
test(name, async () => {
if (config.editor.formAssociated) {
if (TrixEditorElement.formAssociated) {
await callback()
} else {
assert.equal(config.editor.formAssociated, false, "skipping test that requires ElementInternals")
assert.equal(TrixEditorElement.formAssociated, false, "skipping test that requires ElementInternals")
}
})
}
1 change: 0 additions & 1 deletion src/test/test_helpers/fixtures/form_associated_false.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/trix/config/editor.js

This file was deleted.

1 change: 0 additions & 1 deletion src/trix/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export { default as attachments } from "./attachments"
export { default as blockAttributes } from "./block_attributes"
export { default as browser } from "./browser"
export { default as css } from "./css"
export { default as editor } from "./editor"
export { default as fileSize } from "./file_size_formatting"
export { default as input } from "./input"
export { default as keyNames } from "./key_names"
Expand Down
24 changes: 11 additions & 13 deletions src/trix/elements/trix_editor_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ installDefaultCSSForTagName("trix-editor", `\
}`)

export default class TrixEditorElement extends HTMLElement {
static get formAssociated() {
return config.editor.formAssociated
}
static formAssociated = "ElementInternals" in window

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

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

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

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

get validity() {
if (this.#internals) {
return this.#internals.validity
} else {
console.warn("Trix is not configured to support the validity property. Set Trix.config.editor.formAssociated = true")
console.warn("This browser does not support the validity property for trix-editor elements.")
return null
}
}
Expand All @@ -307,7 +305,7 @@ export default class TrixEditorElement extends HTMLElement {
if (this.#internals) {
return this.#internals.validationMessage
} else {
console.warn("Trix is not configured to support the validationMessage property. Set Trix.config.editor.formAssociated = true")
console.warn("This browser does not support the validationMessage property for trix-editor elements.")

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

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

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

return true
}
Expand All @@ -447,7 +445,7 @@ export default class TrixEditorElement extends HTMLElement {

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

Expand Down

0 comments on commit 0e686ba

Please sign in to comment.