trix icon indicating copy to clipboard operation
trix copied to clipboard

Does Trix plan to support `HTMLElement.attachInternals`?

Open seanpdoyle opened this issue 3 years ago • 2 comments

Integrating with HTMLElement.attachInternals could enable <trix-editor> elements to write their contents directly to <form> and FormData instances, without the need to write to a related <input type="hidden"> element.

Furthermore, they could set their validity state with attribute validations like [required], add support for CSS pseudo-classes like :invalid and :disabled, access their assigned <form> element from callbacks.

There are fairly straightforward paths toward changing the Trix codebase to rely on mechanisms built-into ElementInternals, and some clear wins to be had.

Unfortunately (!), there isn't global support just yet, with Safari as the main hold-out. According to the WebKit Bug Tracker, there have been recent changes aimed at implementing ElementInternals.

Has there been any discussion about migrating toward using these tools? Would it be possible to start a migration with feature detection checks for partial support, or would it be best to wait until all browser support has landed before getting started?

seanpdoyle avatar Dec 01 '22 14:12 seanpdoyle

@seanpdoyle AFAIK there's no WIP to implement attachInternals, but I think it's a brilliant idea and would happily accept a patch for it.

Even if the feature is not fully supported in Safari yet it shouldn't change any existing behaviour unless you opt-in to use it. Furthermore, a PR to implement ElementInternals in WebKit was recently merged, so I think it's reasonable to expect support in the not distant future.

afcapel avatar Dec 02 '22 11:12 afcapel

I've opened https://github.com/basecamp/trix/pull/1121 to explore this. @afcapel @jorgemanrubia there are some configuration ergonomics to think through, as well as integration points for third parties like Action Text.

seanpdoyle avatar Jan 16 '24 00:01 seanpdoyle