diff --git a/core/modules/ckeditor5/css/editor.css b/core/modules/ckeditor5/css/editor.css index 5c28250f97..a93a53e0f9 100644 --- a/core/modules/ckeditor5/css/editor.css +++ b/core/modules/ckeditor5/css/editor.css @@ -8,3 +8,8 @@ opacity: 1 !important; fill-opacity: 1 !important; } + +.ck-editor__editable { + min-height: var(--ck-min-height); + max-height: calc(100vh - var(--drupal-displace-offset-top, 0px) - 20px); +} diff --git a/core/modules/ckeditor5/js/ckeditor5.js b/core/modules/ckeditor5/js/ckeditor5.js index 06f4970fd6..a45cad7db4 100644 --- a/core/modules/ckeditor5/js/ckeditor5.js +++ b/core/modules/ckeditor5/js/ckeditor5.js @@ -172,7 +172,20 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len var id = setElementId(element); var ClassicEditor = editorClassic.ClassicEditor; ClassicEditor.create(element, editorConfig).then(function (editor) { + function calculateHeight() { + const element = document.createElement('div'); + element.setAttribute('style', 'visibility: hidden;'); + element.innerHTML = ' '; + editor.ui.view.editable.element.append(element); + const height = element.clientHeight; + element.remove(); + return height; + }; Drupal.CKEditor5Instances.set(id, editor); + // Set the minimum height of the editable area to correspond with the + // user inputted value of number of rows. + const rows = editor.sourceElement.getAttribute("rows"); + editor.ui.view.editable.element.closest('.ck-editor').style.setProperty('--ck-min-height', rows * calculateHeight() + 'px'); if (element.hasAttribute('required')) { required.add(id); element.removeAttribute('required');