From bc24ac570d36001bd51f68f59422f8a93246a0af Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Wed, 7 Feb 2024 12:20:07 -0500 Subject: [PATCH 1/2] Extract delegate for `TrixEditorElement` In preparation for [#1128][], this commit introduces a module-private `Delegate` class to serve as a representation of what form integration requires for the `` custom element. The structure of the `Delegate` class mirrors that of the `TrixEditorElement` from which its contents are extracted. First, there are the properties that mimic those of most form controls, including: * `labels` * `form` * `name` * `value` * `defaultValue` * `type` With the exception of `labels`, property access is mostly proxied through the associated `` element (accessed through its own `inputElement` property). Next, the `Delegate` defines methods that correspond to the Custom Element lifecycle events, including: * `connectedCallback` * `disconnectedCallback` * `setFormValue` The connected and disconnected callbacks mirror that of the `TrixEditorElement` itself. These callbacks attach and remove event listeners for `click` and `reset` events. The `setFormValue` is named to correspond with [ElementInternals.setFormValue][]. Along with introducing this callback method, this commit renames the `TrixEditorElement.setInputElementValue` method to `TrixEditorElement.setFormValue`. In addition to renaming `setInputElementValue`, this commit also defines `TrixEditorElement.formResetCallback` (along with other [empty form callbacks][]), then implements `TrixEditorElement.reset` as an alias. The name mirrors the [ElementInternals.formResetCallback][]. [#1128]: https://github.com/basecamp/trix/pull/1128 [ElementInternals.setFormValue]: https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/setFormValue [empty form callbacks]: https://webkit.org/blog/13711/elementinternals-and-form-associated-custom-elements/ [ElementInternals.formResetCallback]: https://web.dev/articles/more-capable-form-controls#void_formresetcallback --- README.md | 27 +++ assets/index.html | 3 +- karma.conf.js | 2 +- src/test/system/custom_element_test.js | 41 +++- src/test/system/installation_process_test.js | 10 +- src/trix/controllers/editor_controller.js | 2 +- src/trix/elements/trix_editor_element.js | 187 ++++++++++++------- 7 files changed, 196 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index 0133f94a3..9a1cfe6e7 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,33 @@ To populate a `` with stored content, include that content in the a Always use an associated input element to safely populate an editor. Trix won’t load any HTML content inside a `` tag. +## Providing an Accessible Name + +Like other form controls, `` elements should have an accessible name. The `` element integrates with `