You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+55-3
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ This is the approach that all modern, production ready, WYSIWYG editors now take
19
19
20
20
<details><summary>Trix supports all evergreen, self-updating desktop and mobile browsers.</summary><imgsrc="https://app.saucelabs.com/browser-matrix/basecamp_trix.svg"></details>
21
21
22
-
Trix is built with established web standards, notably [Custom Elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements), [Mutation Observer](https://dom.spec.whatwg.org/#mutation-observers), and [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
22
+
Trix is built with established web standards, notably [Custom Elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements), [Element Internals](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals), [Mutation Observer](https://dom.spec.whatwg.org/#mutation-observers), and [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
Place an empty `<trix-editor></trix-editor>` tag on the page. Trix will automatically insert a separate `<trix-toolbar>` before the editor.
52
+
Place an empty `<trix-editor></trix-editor>` tag on the page. If the `<trix-editor>` element is rendered with a `[toolbar]` attribute that references the element by its `[id]`, it will treat that element as its toolbar:
Otherwise, Trix will automatically insert a separate `<trix-toolbar>` before the editor.
53
61
54
62
Like an HTML `<textarea>`, `<trix-editor>` accepts `autofocus` and `placeholder` attributes. Unlike a `<textarea>`, `<trix-editor>` automatically expands vertically to fit its contents.
55
63
56
64
## Integrating With Forms
57
65
66
+
There are two styles of integrating with `<form>` element submissions.
67
+
68
+
### Legacy integration with `<input type="hidden">`
69
+
70
+
Legacy support is provided through an `<input type="hidden">` element paired with an `[input]` attribute on the `<trix-editor>` element.
71
+
58
72
To submit the contents of a `<trix-editor>` with a form, first define a hidden input field in the form and assign it an `id`. Then reference that `id` in the editor’s `input` attribute.
59
73
60
74
```html
@@ -66,7 +80,7 @@ To submit the contents of a `<trix-editor>` with a form, first define a hidden i
66
80
67
81
Trix will automatically update the value of the hidden input field with each change to the editor.
68
82
69
-
## Populating With Stored Content
83
+
####Populating With Stored Content
70
84
71
85
To populate a `<trix-editor>` with stored content, include that content in the associated input element’s `value` attribute.
72
86
@@ -79,6 +93,44 @@ To populate a `<trix-editor>` with stored content, include that content in the a
79
93
80
94
Always use an associated input element to safely populate an editor. Trix won’t load any HTML content inside a `<trix-editor>…</trix-editor>` tag.
81
95
96
+
### Integration with Element Internals
97
+
98
+
Trix can also be configured to integrate with forms through the `<trix-editor>` element's `ElementInternals` instance.
99
+
100
+
First, configure Trix to opt-into its Element Internals support by rendering a `<meta>` element into the document's `<head>`:
Then, to submit the contents of a `<trix-editor>` with a `<form>`, render the element with a `[name]` attribute and its initial value as its inner HTML.
110
+
111
+
```html
112
+
<form…>
113
+
<trix-editorname="content"></trix-editor>
114
+
</form>
115
+
```
116
+
117
+
To associate the element with a `<form>` that isn't an ancestor, render the element with a `[form]` attribute that references the `<form>` element by its `[id]`:
Like other form controls, `<trix-editor>` elements should have an accessible name. The `<trix-editor>` element integrates with `<label>` elements and The `<trix-editor>` supports two styles of integrating with `<label>` elements:
0 commit comments