mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
68bb2650d5
Trix's `<trix-editor>` doesn't support the [form][] property like `<textarea>` or other form fields. For example, consider the following HTML and event listener: ```html <form action="/articles" method="post"> <textarea name="content"></textarea> <button type="submit">Save</button> </form> <script> addEventListener("keydown", ({ key, metaKey, target }) => { if (target.form && key == "Enter" && (metaKey || ctrlKey)) { form.requestSubmit() } }) </script> ``` The `target` (an instance of `HTMLTextAreaElement` relies on the [HTMLTextAreaElement.form][] property for access to its associated `<form>`. While it's usually equivalent to `target.closest("form")`, that isn't always the case. Declaring a `[form]` attribute with another `<form>` element's `[id]` value can associate a field to a `<form>` that is _not an ancestor_. That means that the event listener from above would continue to work with this HTML: ```html <textarea name="content" form="new_article"></textarea> <!-- elsewhere --> <form id="new_article" action="/articles" method="post"> <button type="submit">Save</button> </form> ``` Unfortunately, if the `<textarea>` element were replaced with a `<trix-editor>`, the event listener's reliance on accessing the form as a property would break, since the `<trix-editor>` custom element doesn't declare that property. There is currently a pull request ([basecamp/trix#899][]) to add support for accessing the `form` as a property of the `<trix-editor>` element. The [feedback][] provided on that pull request suggests that we implement the `form` property by delegating to the `<input type="hidden">` element. Currently, `<input type="hidden">` elements constructed by Action Text helpers cannot declare the `[form]` attribute. This commit adds support by special-casing the `options[:form]` key within `ActionText::TagHelper#rich_text_area_tag`. [form]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement#properties [basecamp/trix#899]: https://github.com/basecamp/trix/pull/899#discussion_r618543357 [feedback]: https://github.com/basecamp/trix/pull/899#discussion_r618543357 |
||
---|---|---|
.. | ||
app | ||
bin | ||
db/migrate | ||
lib | ||
test | ||
.gitignore | ||
actiontext.gemspec | ||
CHANGELOG.md | ||
MIT-LICENSE | ||
package.json | ||
Rakefile | ||
README.md |
Action Text
Action Text brings rich text content and editing to Rails. It includes the Trix editor that handles everything from formatting to links to quotes to lists to embedded images and galleries. The rich text content generated by the Trix editor is saved in its own RichText model that's associated with any existing Active Record model in the application. Any embedded images (or other attachments) are automatically stored using Active Storage and associated with the included RichText model.
You can read more about Action Text in the Action Text Overview guide.
License
Action Text is released under the MIT License.