forked from basecamp/trix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes [basecamp#1023][] Replace the requirement for an `<input type="hidden">` element with direct `<form>` integration through built-in support for [ElementInternals][]. According to the [Form-associated custom elements][] section of [More capable form controls][], various behaviors that the `<trix-editor>` element was recreating are provided out of the box. For example, the `<input type="hidden">`-`[input]` attribute pairing can be achieved through [ElementInternals.setFormValue][]. Similarly, the `<label>` element support can be achieved through [ElementInternals.labels][]. [basecamp#1023]: basecamp#1023 [ElementInternals]: https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals [Form-associated custom elements]: https://web.dev/articles/more-capable-form-controls#form-associated_custom_elements [More capable form controls]: https://web.dev/articles/more-capable-form-controls [ElementInternals.setFormValue]: https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/setFormValue [ElementInternals.labels]: https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/labels
- Loading branch information
1 parent
bc24ac5
commit 0088e6c
Showing
17 changed files
with
227 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
import * as config from "trix/config" | ||
|
||
export default () => | ||
`<input id="my_input" type="hidden" value="<div>Hello world</div>"> | ||
<trix-editor input="my_input" autofocus placeholder="Say hello..."></trix-editor>` | ||
config.editor.elementInternals ? | ||
`<trix-editor autofocus placeholder="Say hello..."><div>Hello world</div></trix-editor> | ||
` : | ||
`<input id="my_input" type="hidden" value="<div>Hello world</div>"> | ||
<trix-editor input="my_input" autofocus placeholder="Say hello..."></trix-editor>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import * as config from "trix/config" | ||
import { TEST_IMAGE_URL } from "./test_image_url" | ||
|
||
export default () => | ||
`<trix-editor input="my_input" autofocus placeholder="Say hello..."></trix-editor> | ||
<input id="my_input" type="hidden" value="ab<img src="${TEST_IMAGE_URL}" width="10" height="10">">` | ||
config.editor.elementInternals ? | ||
`<trix-editor autofocus placeholder="Say hello...">ab<img src="${TEST_IMAGE_URL}" width="10" height="10"></trix-editor> | ||
` : | ||
`<trix-editor input="my_input" autofocus placeholder="Say hello..."></trix-editor> | ||
<input id="my_input" type="hidden" value="ab<img src="${TEST_IMAGE_URL}" width="10" height="10">">` |
18 changes: 13 additions & 5 deletions
18
src/test/test_helpers/fixtures/editor_with_toolbar_and_input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
import * as config from "trix/config" | ||
|
||
export default () => | ||
`<ul id="my_editor"> | ||
<li><trix-toolbar id="my_toolbar"></trix-toolbar></li> | ||
<li><trix-editor toolbar="my_toolbar" input="my_input" autofocus placeholder="Say hello..."></trix-editor></li> | ||
<li><input id="my_input" type="hidden" value="<div>Hello world</div>"></li> | ||
</ul>` | ||
config.editor.elementInternals ? | ||
`<ul id="my_editor"> | ||
<li><trix-toolbar id="my_toolbar"></trix-toolbar></li> | ||
<li><trix-editor toolbar="my_toolbar" autofocus placeholder="Say hello..."><div>Hello world</div></trix-editor></li> | ||
</ul> | ||
` : | ||
`<ul id="my_editor"> | ||
<li><trix-toolbar id="my_toolbar"></trix-toolbar></li> | ||
<li><trix-editor toolbar="my_toolbar" input="my_input" autofocus placeholder="Say hello..."></trix-editor></li> | ||
<li><input id="my_input" type="hidden" value="<div>Hello world</div>"></li> | ||
</ul>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
import * as config from "trix/config" | ||
|
||
export default () => | ||
`<form id="ancestor-form"> | ||
<trix-editor id="editor-with-ancestor-form"></trix-editor> | ||
</form> | ||
config.editor.elementInternals ? | ||
`<form id="ancestor-form"> | ||
<trix-editor id="editor-with-ancestor-form"></trix-editor> | ||
</form> | ||
<form id="input-form"></form> | ||
<trix-editor id="editor-with-input-form" form="input-form"></trix-editor> | ||
<trix-editor id="editor-with-no-form"></trix-editor> | ||
` : | ||
`<form id="ancestor-form"> | ||
<trix-editor id="editor-with-ancestor-form"></trix-editor> | ||
</form> | ||
<form id="input-form"> | ||
<input type="hidden" id="hidden-input"> | ||
</form> | ||
<trix-editor id="editor-with-input-form" input="hidden-input"></trix-editor> | ||
<form id="input-form"> | ||
<input type="hidden" id="hidden-input"> | ||
</form> | ||
<trix-editor id="editor-with-input-form" input="hidden-input"></trix-editor> | ||
<trix-editor id="editor-with-no-form"></trix-editor>` | ||
<trix-editor id="editor-with-no-form"></trix-editor>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
document.head.insertAdjacentHTML( | ||
"beforeend", | ||
`<meta name="trix-config-editor-element-internals" content="true"> | ||
`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const config = { | ||
elementInternals: false | ||
} | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.