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
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
58
-
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.
66
+
Like other form controls, the `<trix-editor>` element supports two styles of integrating with `<label>` elements:
67
+
68
+
1. render the `<trix-editor>` element with an `[id]` attribute that the `<label>` element references through its `[for]` attribute:
69
+
70
+
```html
71
+
<labelfor="editor">Editor</label>
72
+
<trix-editorid="editor"></trix-editor>
73
+
```
74
+
75
+
2. render the `<trix-editor>` element as a child of the `<label>` element:
> When rendering the `<trix-editor>` element as a child of the `<label>` element, [explicitly render](#creating-an-editor) the corresponding `<trix-toolbar>` element outside of the `<label>` element.
88
+
89
+
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.
59
90
60
91
```html
61
92
<form…>
62
-
<inputid="x"type="hidden"name="content">
63
-
<trix-editorinput="x"></trix-editor>
93
+
<trix-editorname="content"></trix-editor>
64
94
</form>
65
95
```
66
96
67
-
Trix will automatically update the value of the hidden input field with each change to the editor.
97
+
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]`:
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
-
82
114
## Styling Formatted Content
83
115
84
116
To ensure what you see when you edit is what you see when you save, use a CSS class name to scope styles for Trix formatted content. Apply this class name to your `<trix-editor>` element, and to a containing element when you render stored Trix content for display in your application.
0 commit comments