Я использую следующую функцию для фокусировки редактора с thinyMCE
Это использует jQuery, но было бы легко удалить это и использовать document.querySelectorAll()
. Используйте babel , если вам это нужно в es5.
let focusEditor = function(editorContainer) {
let tinymce;
if (/iPad|iPhone|iPod/.test(navigator.platform)) { return; }
let id = $('.text-editor', editorContainer.innerHTML).first().attr('id');
if (tinymce = window.tinyMCE.get(id)) {
try {
return tinymce.focus();
} catch (error) {
return tinymce.on('init', function() { return this.focus(); });
}
} else {
return $(`#${id}`, editorContainer).focus();
}
}
editorContainer - это любой элемент, окружающий текстовую область tinyMCE, например div с идентификатором 'text-container', который можно вызвать focusEditor($('#text-container'))
или в React focusEditor(React.findDOMNode(this))