diff --git a/core/modules/ckeditor5/css/editor.css b/core/modules/ckeditor5/css/editor.css
index 5c28250f97..969a0a9537 100644
--- a/core/modules/ckeditor5/css/editor.css
+++ b/core/modules/ckeditor5/css/editor.css
@@ -8,3 +8,14 @@
opacity: 1 !important;
fill-opacity: 1 !important;
}
+
+/**
+ * Set the min-height equal to configuration value for the number of rows.
+ *
+ * The `--ck-min-height` value is set on the parent `.ck-editor` element by
+ * JavaScript. We add that there because the `.ck-editor__editable` element's
+ * inline styles are cleared on focus.
+ */
+.ck-editor__main > :is(.ck-editor__editable, .ck-source-editing-area) {
+ min-height: var(--ck-min-height);
+}
diff --git a/core/modules/ckeditor5/js/ckeditor5.js b/core/modules/ckeditor5/js/ckeditor5.js
index 0dfd4f1285..dae0c4d361 100644
--- a/core/modules/ckeditor5/js/ckeditor5.js
+++ b/core/modules/ckeditor5/js/ckeditor5.js
@@ -370,9 +370,37 @@
ClassicEditor.create(element, editorConfig)
.then((editor) => {
+ /**
+ * Injects a temporary
into the CKeditor and returns its height.
+ *
+ * @returns {number} - the height of a div in pixels.
+ */
+ function calculateLineHeight() {
+ 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;
+ }
+
// Save a reference to the initialized instance.
Drupal.CKEditor5Instances.set(id, editor);
+ // Set the minimum height of the editable area to correspond with the
+ // user inputted value of number of rows. We attach this custom property
+ // to the `.ck-editor` element, as that doesn't get its inline styles
+ // cleared on focus. The editable element is then set to use this
+ // property within the stylesheet.
+ const rows = editor.sourceElement.getAttribute('rows');
+ editor.ui.view.editable.element
+ .closest('.ck-editor')
+ .style.setProperty(
+ '--ck-min-height',
+ `${rows * calculateLineHeight()}px`,
+ );
+
// CKEditor 4 had a feature to remove the required attribute
// see: https://www.drupal.org/project/drupal/issues/1954968
if (element.hasAttribute('required')) {
diff --git a/core/modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5EditorHeightTest.js b/core/modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5EditorHeightTest.js
new file mode 100644
index 0000000000..a041599ba3
--- /dev/null
+++ b/core/modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5EditorHeightTest.js
@@ -0,0 +1,111 @@
+module.exports = {
+ '@tags': ['core', 'ckeditor5'],
+ before(browser) {
+ browser.drupalInstall({ installProfile: 'minimal' });
+ },
+ after(browser) {
+ browser.drupalUninstall();
+ },
+ 'Test page': (browser) => {
+ browser.drupalLoginAsAdmin(() => {
+ browser
+ // Enable required modules.
+ .drupalRelativeURL('/admin/modules')
+ .click('[name="modules[ckeditor5][enable]"]')
+ .click('[name="modules[field_ui][enable]"]')
+ .submitForm('input[type="submit"]') // Submit module form.
+ .waitForElementVisible(
+ '.system-modules-confirm-form input[value="Continue"]',
+ )
+ .submitForm('input[value="Continue"]') // Confirm installation of dependencies.
+ .waitForElementVisible('.system-modules', 10000)
+
+ // Create new input format.
+ .drupalRelativeURL('/admin/config/content/formats/add')
+ .waitForElementVisible('body')
+ .updateValue('[data-drupal-selector="edit-name"]', 'test')
+ .pause(500) // Wait for machine name to update.
+ .click(
+ '[data-drupal-selector="edit-editor-editor"] option[value=ckeditor5]',
+ )
+ .waitForElementVisible(
+ '[data-drupal-selector="edit-editor-settings-toolbar"]',
+ ) // Wait for Ck5 settings to be visible.
+ .submitForm('input[type="submit"]')
+
+ // Create new content type.
+ .drupalRelativeURL('/admin/structure/types/add')
+ .waitForElementVisible('body')
+ .updateValue('[data-drupal-selector="edit-name"]', 'test')
+ .pause(500) // Wait for machine name to update.
+ .submitForm('input[type="submit"]')
+ .waitForElementVisible('[data-drupal-messages]')
+
+ // Navigate to the create content page and measure height of the editor.
+ .drupalRelativeURL('/node/add/test')
+ .waitForElementVisible('body')
+ .execute(
+ // eslint-disable-next-line func-names, prefer-arrow-callback, no-shadow
+ function () {
+ const height = document.querySelector(
+ '.ck-editor__editable',
+ ).clientHeight;
+
+ // We expect height to be 162, but test to ensure that it's greater
+ // than 150. We want to ensure that we don't hard code a very specific
+ // value because tests might break if styles change (line-height, etc).
+ // Note that the default height for CKEditor5 is 47.
+ return height > 150;
+ },
+ [],
+ (result) => {
+ browser.assert.ok(
+ result.value,
+ 'Editor height is set to 9 rows (default).',
+ );
+ },
+ )
+
+ // Double the editor row count.
+ .drupalRelativeURL('/admin/structure/types/manage/test/form-display')
+ .waitForElementVisible('body')
+ .click('[data-drupal-selector="edit-fields-body-settings-edit"]')
+ .waitForElementVisible(
+ '[data-drupal-selector="edit-fields-body-settings-edit-form-settings-rows"]',
+ )
+ .updateValue(
+ '[data-drupal-selector="edit-fields-body-settings-edit-form-settings-rows"]',
+ '18',
+ )
+ .click(
+ '[data-drupal-selector="edit-fields-body-settings-edit-form-actions-save-settings"]',
+ ) // Save field settings.
+ .waitForElementVisible(
+ '[data-drupal-selector="edit-fields-body"] .field-plugin-summary',
+ )
+ .click('[data-drupal-selector="edit-submit"]')
+ .waitForElementVisible('[data-drupal-messages]')
+
+ // Navigate to the create content page and measure height of the editor.
+ .drupalRelativeURL('/node/add/test')
+ .execute(
+ // eslint-disable-next-line func-names, prefer-arrow-callback, no-shadow
+ function () {
+ const height = document.querySelector(
+ '.ck-editor__editable',
+ ).clientHeight;
+
+ // We expect height to be 324, but test to ensure that it's greater
+ // than 300. We want to ensure that we don't hard code a very specific
+ // value because tests might break if styles change (line-height, etc).
+ // Note that the default height for CKEditor5 is 47.
+ return height > 300;
+ },
+ [],
+ (result) => {
+ browser.assert.ok(result.value, 'Editor height is set to 18 rows.');
+ },
+ );
+ });
+ },
+};
diff --git a/interdiff-50-52.txt b/interdiff-50-52.txt
new file mode 100644
index 0000000000..f1ba58e947
--- /dev/null
+++ b/interdiff-50-52.txt
@@ -0,0 +1,12 @@
+diff --git a/core/modules/ckeditor5/css/editor.css b/core/modules/ckeditor5/css/editor.css
+index bac24a8608..969a0a9537 100644
+--- a/core/modules/ckeditor5/css/editor.css
++++ b/core/modules/ckeditor5/css/editor.css
+@@ -16,6 +16,6 @@
+ * JavaScript. We add that there because the `.ck-editor__editable` element's
+ * inline styles are cleared on focus.
+ */
+-.ck-editor__editable {
++.ck-editor__main > :is(.ck-editor__editable, .ck-source-editing-area) {
+ min-height: var(--ck-min-height);
+ }