tinymce / tinymce-webcomponent

MIT License
15 stars 7 forks source link

Setting value only works sometimes #33

Open confususs opened 1 year ago

confususs commented 1 year ago

First of all, thanks for building this web component. It makes the life of me and my colleagues a lot easier :smile:.

After implementing it I encountered some cases where the value setter didn't propagate the new value correctly to the TinyMCE editor. The value only seems to be propagated when the internal _status is "Ready".

It would be great if we could set this value regardless of what the status is, so that we are able to set the value prior to 'Ready', or even during initializing.

This is the way we go around it currently:

const tinyMCEWebComponent = this.querySelector('tinymce-editor');
if (tinyMCEWebComponent._editor) {
  const target = tinyMCEWebComponent._editor.getElement();
  if (target) {
    target.value = value;
  }
}

// Only set the textContent when the status is 'Raw', which is the state
// prior to Initializing. When initializing, it is often too late to
// set the value to the textContent since it is read immediately after it switched state to Initializing.
if (tinyMCEWebComponent._status === 0) { // 0 equals 'Raw'. Other states are 'Initializing' and 'Ready'.
  tinyMCEWebComponent.textContent = value;
}

// Always try to set the value through the setter of the tinymce web
// component. It has some checks internally, so it is only setting the
// value when the state is 'Ready'.
tinyMCEWebComponent.value = value;

Which I'd like to avoid :slightly_smiling_face:

exalate-issue-sync[bot] commented 1 year ago

Ref: INT-2958