The default field widget settings for the body field are 9 rows and 3 summary rows. When you create a new node with CKEditor 5, the body field is only 1 row (when no content is entered).

This looks odd and unexpected and has usability implications, as it does not inform the editor that long form content is expected within this field.

two browser windows side by side. on the left empty node edit form with ckeditor5 text format on the right ckeditor5 field widget settings

When content is entered within the field, the body field will expand indefinitely. This behavior will be handled in separate issues:

Steps to reproduce

  1. Navigate to the article form display at /admin/structure/types/manage/article/form-display , and note that the body field is set to display 9 rows (which is the default setting).
  2. Add article node.
  3. Notice that CKEditor5 only has one row visible.

Manual testing steps

  1. Take before screenshots
  2. Apply the patch
  3. Ensure that your input format’s CKEditor configuration has the “Source Editing” (aka “View Source”) button added.
  4. Add article node.
  5. Notice that CKEditor5 now has multiple rows visible. The total height of the editable area should be set to 216px, which is the the height of an unstyled div (24px * 9). Note in other themes this value can change due to font sizes.
  6. Take a screenshot
  7. Add content into CKEditor. Make sure it works as expected.
  8. Test media, and captions.
  9. Clear the content
  10. Switch to the Source View by clicking the “Source Editing” button. Ensure that the size of the source view input is does not change.
  11. Take screenshots
CommentFileSizeAuthor
#114 3241295-d10.1.6-114.patch872 bytesedmund.dunn
#111 Body has correct 5 rows.jpg32.98 KBseeduardo
#108 3241295-d10.0.9-108.patch4.19 KBnaveenvalecha
#106 Screenshot from 2023-04-19 11-44-36.png25.07 KBvikas shishodia
#101 3241295-d9.5-101.patch13.42 KBclaudiu.cristea
#101 3241295-d9.5-101.interdiff.txt1.53 KBclaudiu.cristea
#100 3241295-d9.5-100.patch13.42 KBclaudiu.cristea
#91 3241295-ckeditor-height-9.5.x.patch4.76 KBmherchel
#86 interdiff.txt3.95 KBlauriii
#83 interdiff-79-83.txt1.6 KBmherchel
#83 3241295-d10-83.patch11.86 KBmherchel
#82 after.png19.04 KBWim Leers
#82 before.png16.84 KBWim Leers
#79 interdiff-74-79.txt772 bytesmherchel
#79 3241295-d10-79.patch11.82 KBmherchel
#74 interdiff-69-74.txt1.25 KBmherchel
#74 3241295-d10-74-test-only-FAIL.patch7.87 KBmherchel
#74 3241295-d10-74.patch11.06 KBmherchel
#69 interdiff-65-69.txt4.72 KBmherchel
#69 3241295-d10-69-test-only-FAIL.patch7.82 KBmherchel
#69 3241295-d10-69.patch11.02 KBmherchel
#66 After patch - body field.png96.64 KBDeepaliJ
#66 Before patch - body field.png66.73 KBDeepaliJ
#65 interdiff-64.65.txt712 bytesmherchel
#65 3241295-d10-65.patch10.86 KBmherchel
#64 interdiff-55-64.txt5.45 KBmherchel
#64 3241295-d10-64-test-only-FAIL.patch7.65 KBmherchel
#64 3241295-d10-64.patch10.85 KBmherchel
#62 linebreaks.jpg127.02 KBrkoller
#62 linewrap.jpg166.62 KBrkoller
#55 3241295-d10-55-test-only-FAIL.patch7.65 KBmherchel
#55 3241295-d10-55.patch10.16 KBmherchel
#54 interdiff-52-54.txt4.47 KBmherchel
#54 3241295-d10-54-test-only-FAIL.patch7.35 KBmherchel
#54 3241295-d10-54.patch9.85 KBmherchel
#53 interdiff-50-52.txt494 bytesmherchel
#52 3241295-d10-52.patch7.92 KBmherchel
#50 3241295-d10-49-test-only-FAIL.patch4.76 KBmherchel
#50 3241295-d10-49.patch7.22 KBmherchel
#47 interdiff-36-47.txt2.55 KBmherchel
#47 3241295-10.x-47.patch2.46 KBmherchel
#44 3241295-44.patch3.14 KB_utsavsharma
#44 interdiff_41-44.txt2.72 KB_utsavsharma
#43 ck5.jpg68.49 KBgaurav-mathur
#43 ck_5.jpg55.81 KBgaurav-mathur
#41 3241295-row-weights-41.patch1.77 KBglynster
#36 3241295-36.patch1.95 KBmherchel
#33 3241295-row-weights-33.patch347 bytesglynster
#32 3241295-row-weights-32.patch1.17 KBglynster
#31 3241295-row-weights-31.patch1.18 KBglynster
#24 3241295-24.patch1.21 KB_utsavsharma
#19 3241295-row-weights-19.patch1.16 KBEmil Stoianov
#16 ck5.png79.23 KBmherchel
#8 ckeditor5demo.png98.97 KBrkoller
#16 ck4.png79.81 KBmherchel
ckeditor5_content.png287.51 KBrkoller
#8 ckeditor5demo_extraLong.png13.61 KBrkoller
#8 ckeditor5demo_nocontent.png8.77 KBrkoller
ckeditor5_no_content.png248.22 KBrkoller
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rkoller created an issue. See original summary.

Wim Leers’s picture

Wim Leers’s picture

Status: Active » Postponed (maintainer needs more info)
Wim Leers’s picture

Title: CKEditor 5 isn't respecting field widgets row settings » [upstream] CKEditor 5 isn't respecting field widgets row settings
Project: CKEditor 5 » Drupal core
Version: 1.0.x-dev » 9.3.x-dev
Component: User interface » ckeditor5.module
Status: Postponed (maintainer needs more info) » Postponed
Issue tags: +Needs upstream feature

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

rkoller’s picture

i've finally revisited the issue - your last comment slipped through apologies. :/ somehow it looks the issue you have linked is closed upstream for a while now as well as a related one linked in it. and based on the comment by reinmar https://github.com/ckeditor/ckeditor5/issues/636#issuecomment-459255509 it doesn't looks like they intend to provide something like the mentioned config.height option. am i reading it correctly that his recommended approach would be to set the height of the editor window by css? then the upstream label might be not necessary anymore? would it make sense to implement that directly in drupal?

Wim Leers’s picture

am i reading it correctly that his recommended approach would be to set the height of the editor window by css?

That is my interpretation too.

then the upstream label might be not necessary anymore? would it make sense to implement that directly in drupal?

Well … no … how do we convert rows="N" which essentially means "N lines of text" to a concrete height?

The point is that we shouldn't be implementing this here in Drupal, it should be implemented upstream.

There just is no reliable way to implement this, which is also why CKEditor is trying to not implement it upstream.

If you start to enter content now the summary field behaves as expected with CKEditor 4 & 5 - only 3 rows are visible and as soon as more than 3 lines are entered a scrollbar is shown. For CKEditor 5 it behaves unexpected again.

The summary field does not use CKEditor 4 or 5, it's just a plain <textarea>. This is why it "works": because it has a predictable line height.

Sorry to not have better news 😔

rkoller’s picture

thanks for the confirmation. and i can understand and agree that if implemented it should be still happen upstream. but from a usability perspective i consider it sort of problematic but totally reasonable and understandable if there isnt a reliable way to determine the height of the ckeditor5 field at the moment.
always wondered how ckeditor5 could have such a nice fitting demo page up with an appropriate height for the demo field.
ckeditor5 demo page on ckeditor.com
BUT i've revisited the page today and just removed the demo content and is behaving in the same way like it does in drupal a single lined field.
ckeditor5 demo page on ckeditor.com with all the default content removed resulting in a one line high ckeditor5 window
out of curiosity i've created a text snippet with 50 numbered lines and then copied and pasted that. ended up with a 1400 line text field stretching the actual length of the page into "infinity" (mind the the scroller and it position in context to the height of the whole scrollbar) ;)
ckeditor5 demo page on ckeditor.com 1400 lines long numbered in blocks of 50 leading up to an extra long page
imagine the whole field filled with actual complex content and having 3 or 4 more ckeditor 5 fields plus several other elements in a drupal content type with limitless expanding ckeditor fields i consider the navigation between the different fields or the page in general might become difficult and challenging. and from a performance perspective does it make a difference if you have lets say three ckeditor5 fields that would be limited in height with only a section of each fields content visible in contrast to the current state where you have expanded ckeditor5 fields to the entire length of its content?

Wim Leers’s picture

Reported again at #3273744: CKE5 Respect a MINIMUM size for the CK-enabled textarea:

At the moment, CKE5 textarea do not respect any configurable sizes, although as a site builder I am provided with a UI to configure so.

[…]

Using the standard install profile as an example here, you are provided a UI to configure a number of rows for your textarea. Example is shown here with the default body field of the default article node type available at /admin/structure/types/manage/article/form-display
body field configuration

Enter 9 here for instance : on CKE4 this is not respected, but the default size is hardcoded (within CKEditor I suppose) to 5 :
CKE4 multilign by default

After conversion to CKE5, this very same field as a size of 1 which make it weird to people used to Drupal.
CKE5 multilign by default

All I can do here is say: please read https://github.com/ckeditor/ckeditor5/issues/636 and articulate how you believe this could be addressed upstream.

Wim Leers credited Dom..

Wim Leers’s picture

Wim Leers’s picture

@rkoller in #8:

out of curiosity i've created a text snippet with 50 numbered lines and then copied and pasted that. ended up with a 1400 line text field stretching the actual length of the page into "infinity" (mind the the scroller and it position in context to the height of the whole scrollbar) ;)
ckeditor5 demo page on ckeditor.com 1400 lines long numbered in blocks of 50 leading up to an extra long page
imagine the whole field filled with actual complex content and having 3 or 4 more ckeditor 5 fields plus several other elements in a drupal content type with limitless expanding ckeditor fields i consider the navigation between the different fields or the page in general might become difficult and challenging. and from a performance perspective does it make a difference if you have lets say three ckeditor5 fields that would be limited in height with only a section of each fields content visible in contrast to the current state where you have expanded ckeditor5 fields to the entire length of its content?

For that, @Dom. opened #3273755: CKEditor 5 should not grow to infinite height actually — let's continue that aspect in there? 🤞

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mherchel’s picture

Status: Postponed » Active
Issue tags: +Usability

To me this is a pretty big usability issue.

I talked to @lauriii and floated this idea. He seemed fairly receptive, so re-opening.

1. Expose the row settings to the JS if it's not already
2. Calculate the height of the CKEditor (something like row count * REM height * line-height)
3. Set that value to a custom property within CKEditor
4. Use that custom property to set a min-height within the stylesheet.

Wim Leers’s picture

@mherchel That makes me curious why this was not a big usability issue in CKE4 for you? Same challenge there: #2877527: Make CKEditor (approximately) reflect the rows setting of a field.

mherchel’s picture

FileSize
79.81 KB
79.23 KB

Good question.

The reason is because (at least for the default body field), the field size is tall in D9. IMO this gives the content editor a sense of the purpose of the field (the body field is meant for long form content).

While in Drupal 10, the content editor does not get this sense of purpose.

Does this make sense?

Wim Leers’s picture

Ah, yes, that does make sense!

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Emil Stoianov’s picture

Implements approximate number of rows spacing in the Ckeditor5 initial load.
The editor area still resizes on click in side it to editors default behavior.

As inspiration served this module https://www.drupal.org/project/ckeditorheight for Ckeditor4

Wim Leers’s picture

Status: Active » Needs review
Issue tags: +Needs tests, +Needs frontend framework manager review, +Needs accessibility review

Very interesting, @Emil Stoianov! And since that has a fairly solid amount of usage, we may actually consider that in Drupal core… hoping @nod_ or @lauriii will review this 🤞

smustgrave’s picture

Status: Needs review » Needs work

Moving to NW for all the tags needed. Also patch #19 failed.

nod_’s picture

+++ b/core/modules/ckeditor5/js/ckeditor5.js
@@ -218,8 +218,16 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
+        var toPx = function() {
+          var element = jQuery('<div style="display: none; font-size: 1.5em; margin: 0; padding:0; height: auto; line-height: 1; border:0;">&nbsp;</div>').appendTo('body');
+          var height = element.height();
+          element.remove();
+          return height;
+        };

Could we get the height of the ckeditor text area instead of a whole new thing? Since the textarea only show one line we can get the are height "easily" maybe? That would account for styling differences between wysiwyg areas in case there is one

Patch Doesn't apply to 10.1.x

RgnYLDZ’s picture

I think the simplest (but not most flexible) way would be to set a min-height to .ck-editor in the admin theme like this;

.ck-content{
  min-height: 300px;
}

So this way the editor is in a minimum height on initial and it will expand to the bottom if there is more content entered.

Edit: This is only a quick fix for people with urgent needs :)

_utsavsharma’s picture

Rerolled for 10.1.x.
Please review.

geek-merlin’s picture

@WimLeers said in #20:
> Very interesting! And since [ckeditotheight.module] has a fairly solid amount of usage, we may actually consider that in Drupal core… hoping @nod_ or @lauriii will review this.

Although being late to the party, as the author of ckeditorheight i can give some 5 cent.

In all that discussion, we had that point that "there is no undisputable way to convert rows into heught".
The nerd in me said yes, the practician smiled and said nope.
So created ckeditorheight, did not look for two years, and now i'm impressed by the usage, too.
Looks like the approach works for some.

So what does it do? It calculates the height like this:

$height = $offset + $lineHeight * $rows;

Also the $unit (pt, em, rem) is configurable, and "disable autogrow".

That's it, no rocket science, just linear algebra. Any ckeditor5-Api versatile person should be able to do that in half a day. (I'm not and the decorator voodoo i did in ckeditorheight (sorry kittens) likely originated fom my lack of Api-grokking.)

I can't put free time into this atm. But:
- I'd love to see this in core
- I postponed and pointed the ckeditorheight issue to this one
- IF core maintainers feel like this should be pioneered in contrib, feel free to create a MR in the related issue.

tgoeg’s picture

Just a sysadmin here, but please also take a look at https://www.drupal.org/project/ckeditor/issues/2877527#comment-14810796 which might be of interest implementation wise.

Regarding the use cases:
I have another one here. I don't want the editor to have a given minimum height and expect it to grow, quite the opposite, I want one single, fixed line.
Might sound strange, eh? I need it for an a11y hack as Drupal has no way of marking up different languages in the title field of content (as it does not allow HTML; which should be tackled elsewhere). We fell through an a11y audit because of this. Now we have an additional title_html field that has just one line (realized with ckeditorheight, thank you for developing it!) which overrides the actual title field if filled.

Regarding the patch:
I don't know if jQuery will be included/be part of CKEditor forever. Maybe element should be determined with vanilla ES6?

mgifford’s picture

@tgoeg have you seen the Language of Parts under CKEditor?

I've done lots with multi-lingual sites. Why would you want to have a title different than the body of the content? How are you adding languages using a title with your work-around?

tgoeg’s picture

Seems that wasn't clear enough, sorry.
We need to mark up multiple mixed languages in one title.
I am from Austria and there are many terms we tend to borrow from English, "Download" for example.
If we do not add correct markup for screen readers to understand this is an English term, it will be read out as something like "Dovnloh-ahd', which might be funny but not that helpful.
You need to correctly mark parts in other languages to get web accessibility certifications, which is easy with CKEditor's language button (which just generates a <span lang="en">Download</span> for example).
As this is HTML, I cannot put this into Drupal's default title field, however.
Title fields that embrace several rows are not only unexpected or distracting, they also promote entering the whole body right into this rich text field.
And that's where we're back on topic, sorry for the rather far-reaching excursion :-)

mgifford’s picture

Now I am a unilingual person, but have been building multi-lingual websites in Drupal for over a decade. Mostly also keeping in mind accessibility concerns.

So rather than using something 'herunterladen' (I'm pretty sure I'm messing this up), people want to use the term 'download'

So, using Google Translate authors want to say something like "Download our current annual report", but rather than just using 100% German, 'Laden Sie unseren aktuellen Jahresbericht herunter', they want to use something more "modern" which sadly (my bias) has English sprinkled in, like 'Download Sie unseren aktuellen Jahresbericht'.

But because the page is in German, the screen reader user comes across the word "Download" the screen reader's library tries to read this in German and so pronounces it as you would in German "Dovnloh-ahd", vs how German people generally pronounce this English word, which would obviously be more like the English "Download"

So, you want a title the word "Download" isolated in English, so it is more like <h1><span lang="en">Download</span> Sie unseren aktuellen Jahresberich<h1>, so that it reads correctly?

If this is the case, interesting... Might be best to have a custom module that allows a user to include HTML in the text field. I think in most cases the assumption is that the title is just plain text.

tgoeg’s picture

Right, that's it.
But I don't think that's a German issue at all. English also has this requirement, with our national accessibility certification authority at least.
You also have to designate french words in English, think 'hors d'œvre' for example or the masses of other loan words that exist in English as well (be they French for BE or Spanish for AE for example)

The general assumption of a title field being plain text is ... plain wrong :-)
This should go into Drupal core, and not into a module, I think, as I should be able to create accessible sites ootb.

There are words that don't even have any translation. "Download" probably wasn't that good an example, maybe - in German at least - Smartphone, Computer, etc. The corresponding translations would be something like "intelligent telephone" or "calculator", which no-one would understand.

But we're getting off topic.

Entering a row amount for a CKEditor field should be respected, be it for a bigger or a smaller (even 1-row) setting.

glynster’s picture

We ran into this issue for Drupal 9.5 when we migrated to ckeditor5. Patch 3241295-row-weights-19.patch does not work with Drupal 9.5. Here is an updated patch along with a maxHeight as well.

glynster’s picture

After some more playing around I think setting minHeight to 100vh is the most useful. This way no matter what size device/window you are on/using you can benefit.

glynster’s picture

After more tests we discovered the style applied via JS is removed once the textarea is focused. We think the better approach is pure css. Latest patch attached.

zcht’s picture

Thanks for the patches @glynster

I first tried the CSS solution, unfortunately it did not have the desired success.

So afterwards I tried the Js solution, unfortunately it only works to some extent. In my case I use paragraphs with a text field, so in a node a new text paragraph is inserted, the edit field is clearly larger, whereby it does not correspond to the actual value of 15 rows. As soon as the mouse curser is placed in this field, the field is automatically reduced to 1 row.

This also happens with existing text paragraphs that already contain content. A maximum height is triggered, when the mouse is clicked the height is reduced to the amount of text.

geek-merlin’s picture

@glynster: I don't see how #33 has variable height, but #32 has a good direction imho.
We can bikeshed if that kind of autodetecting line height can work, but that's detail (we can still make configurable like ckeditorheight.module, with fallback to autodetect).
This should use CKEditor API though (know, i don't know the api but asking on StackOverflow or CKEditor issue queue might help).
And of course... https://youmightnotneedjquery.com/

mherchel’s picture

Status: Needs work » Needs review
FileSize
1.95 KB

Attached is a working patch that solves the minimum height (setting the value to similar to the method in #31), and also setts the max height using both the viewport height and the new --drupal-displace-offset-top CSS variable that takes into account the toolbar height.

Note that I haven't extensively tested this.

zcht’s picture

@mherchel is it possible that you also create a patch for drupal 9.5? then i could test it directly for the drupal version.

glynster’s picture

@geek-merlin I guess in my eye using vh with css is a variable height based on the users display window. In our usercase it becomes super userful. Min height is not really a concern as apposed to the max height issue. Having to scroll up to the top of the textarea to get to the editor becomes a pain to work with over time.

@mherchel thanks for your patch however the issue remains that once the textarea is focused the listener removes all styles.

glynster’s picture

I wonder if it makes more sense to allow the option for Balloon, Balloon Block or inline. In our usercases it is about getting to the editor without the need to scroll to the top of the page every time. When you deal with very long articles this gets tiresome. CKeditor4 took care of this without you even knowing it.

https://ckeditor.com/ckeditor-5/demo/#balloon

Perhaps @mherchel can keep reworking his patch to accomodate a js listener so the inline style remains? Then we could have a win win? I would also love to get a working patch for Drupal 9.5.

mherchel’s picture

@mherchel thanks for your patch however the issue remains that once the textarea is focused the listener removes all styles.

I work around this by adding a custom property to the parent .ck-editor element (instead of the .ck-editor__editable element), and then invoke that through the actual stylesheet.

Test it out, it seems to work well for me.

glynster’s picture

@mherchel you were completely right. I was manually testing this on Drupal 9.5 and forget to add the css. Totally stupid of me. Here is @mherchel patch for Drupal 9.5. It works well for us.

gaurav-mathur’s picture

Assigned: Unassigned » gaurav-mathur
gaurav-mathur’s picture

Assigned: gaurav-mathur » Unassigned
FileSize
55.81 KB
68.49 KB

Verified and tested patch #33 on the drupal 9.5.x-dev version and the patch applied successfully.

_utsavsharma’s picture

Fixed CCF for #41 for 9.5.x.
Please review.

glynster’s picture

@_utsavsharma I wondered about es6! Thanks for the update. Still works well. Please test everyone and report back.

mherchel’s picture

Title: [upstream] CKEditor 5 isn't respecting field widgets row settings » CKEditor 5 isn't respecting field widgets row settings
Issue tags: -Needs upstream feature

I verified the approach in #36 with CKEditor5 maintainer @lauriii.

A couple notes.

  • Keep the max-height issue separate
  • I'm assuming we'll need to test this somehow.
mherchel’s picture

Attached is an updated patch for #36. This fixes some code formatting, removes the max-height, and adds very generous comments.

Still needs tests

glynster’s picture

@mherchel can you add in the es6 js file as well? Then the custom commands will pass like @_utsavsharma did.

mherchel’s picture

Drupal 10 doesn't use the es6 files anymore (only D9 does). See https://www.drupal.org/about/core/blog/javascript-build-process-removed

It's failing because I wasn't using template literals.

If we do a Drupal 9 patch, we'll. need it.

Anyway, new patch incoming (with tests!!!!)...

mherchel’s picture

Status: Needs review » Needs work

Test should pass on above, but I found a couple more (easily fixed) issues while manually testing:

  • When switching to "view source", the rows height is not respected
  • When adding a caption to an image, the figcaption also has a .ck-editor__editable CSS class, which gets the full height. We need to exclude this from the CSS selector.
mherchel’s picture

Status: Needs work » Needs review
FileSize
7.92 KB

Fixed the issues in found in #51.

Lets see what the tests say with this.

mherchel’s picture

FileSize
494 bytes

Interdiff for above.

mherchel’s picture

🤦‍♂️ I included the interdiff in the patch above.

Either way, in this patch I cleaned up the tests a bit to make them more robust, including checking the height of the source code editor.

mherchel’s picture

Cspell error above. This new patch modifies the dictionary.txt to add "sourceediting"

geek-merlin’s picture

Status: Needs review » Needs work

Nice!
Reviewing #55:
- Code looks solid
- Contains a nightwatch test
- Test-only patch fails that test (see console)
- Patch-plus-test is green

So according to the test, patch fixes the issue.

What's missing to RTBC is
- someone test this manually and provide screenshots for the maintainers to review
- someone text a change record

NW for that, after that imho RTBC.

mherchel’s picture

Category: Feature request » Bug report
Issue tags: -Needs tests +Needs manual testing

Thanks for the review @geek-merlin!

Setting back to Needs Review per https://www.drupal.org/docs/develop/issues/fields-and-other-parts-of-an-... because the patch [currently] does not need work.

I'm also setting this to a Bug report, because this is very much a bug IMHO.

We still need manual testing (with screenshots). Adding the Needs manual testing tag.

mherchel’s picture

Status: Needs work » Needs review
geek-merlin’s picture

Issue tags: +Needs change record
mherchel’s picture

Issue summary: View changes

Editing issue summary to summarize results and add testing instructions. I'm narrowing the scope of this to only fixing the initial height of the editor. The maximum height issues can be handled separately in #3273755: CKEditor 5 should not grow to infinite height and #3326193: CKEditor 5 can grow past the viewport when there is a lot of content

mherchel’s picture

Issue summary: View changes
rkoller’s picture

FileSize
166.62 KB
127.02 KB

I've applied the latest patch from #55 to a Drupal 10.1.x-dev install. The patch applied cleanly. I've then manually tested the patch and created the requested screenshots (the before screenshot is already in the issue summary).

In the edit form display-widget for the body field i've set the rows value to 7 and the value for the summary rows to 5 and checked Always show the summary field. The value for the summary-field is exactly in line with the set summary rows setting (see both screenshots). "Problem" is the body field. If i enter text with no line breaks and let the text wrap until the field would expand in height the first time, due to too much content entered, i would get up to 5 lines. two lines less than set in the rows settings.

body widget setting and node edit form window next to each other

if i enter ascending numbers with line breaks, like in the summary field, i get only up to three lines, in contrast to the seven lines set.

body widget setting and node edit form window next to each other

That mismatch is a bit of a problem. if you try to set up a certain experience for the content editor as a site builder and you have a certain height for a certain amount of content in mind. ideally it should be predictable for the site builder but that way it is sort of an try and error. but on the other hand it is also trickier than initially thought on a closer look. because how many lines fit into the field before it expands depends on the number of line breaks entered (on line break the paragraph gets wrapped into a p tag and each p tag has margins). you will never know the content an editor will enter. let's say you have set the value of rows to 20 so the number of actual rows entered before the field expands differs significantly if you have no line break, two line breaks or even twenty. and twenty rows wouldn't currently fit into the field if rows is set to twenty anyway currently.

i've discussed the matter with @mherchel in https://drupal.slack.com/archives/C1AFW2ZPD/p1671812212201099. he wondered if the following would make sense instead for calculating the height: Maybe instead of inserting a <div> to measure, I should inject a <p> and measure that + its margin. or i wondered perhaps it would make sense to define the constraints for the calculation in the field description. that the calculation is solely based on the without line break scenario and that way site builders are being "warned"?

and one other detail i've noticed. would it make sense to update the field description to the rows and summary rows fields? currently it says Text editors (like CKEditor) may override this setting.. Does that still apply or could it be updated or removed when this patch lands or is it still a general point to mind with other editors?

mstrelan’s picture

Re: 62 I think it's important to distinguish between a line break and a paragraph. Using shift+enter should get you a line break (<br>) which should be equivalent in height to letting the text wrap on to the next line. A new paragraph in plain text would be equivalent to two line breaks.

Since the cke default would usually be a paragraph tag I think it makes sense to measure the line-height of a <p> tag, multiply it by number of rows and apply the top margin and bottom margin.

Note that in the case of a longer paragraph with no line breaks including the bottom margin might give you a little bit extra height to play with, but at that point I guess cke would grow to accommodate the bottom margin.

mherchel’s picture

Since the cke default would usually be a paragraph tag I think it makes sense to measure the line-height of a

tag, multiply it by number of rows and apply the top margin and bottom margin.

Yeah, I'm coming around to that same opinion. Thanks for the input.

New patch attached that does all of this (please test).

Instead of injecting a <div>, it injects a <p> tag and then calculates its height and margins (accounting for collapsing margins), and outputs the correct height. It seems to work great for me.

Please test away :D

mherchel’s picture

Adding in the radix parameter into parseInt. No changes to the test, so not re-uploading that by itself.

DeepaliJ’s picture

Tested and applied patch #65 on Drupal 10.1.x-dev.
Patch applied cleanly.
Issues got fixed after applying the patch

Refer to the attached screenshots
Before patch:
before

After patch:
after

RTBC +1

ckrina’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs manual testing

Just tested #65 locally and it works perfect. Thanks!

Since the scope now is to set the min-height only, I think this is fine to commit now. Since the patch is not introducing any regression (max-height is not changed in this issue) and it actually improving the UX setting the min-height, I'll move this to RTBC.

Wim Leers’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs accessibility review
  1. +++ b/core/modules/ckeditor5/js/ckeditor5.js
    @@ -370,9 +370,55 @@
    +           * Injects a temporary <p> into CKeditor and then calculates the entire
    

    s/CKeditor/CKEditor/

  2. +++ b/core/modules/ckeditor5/js/ckeditor5.js
    @@ -370,9 +370,55 @@
    +            element.setAttribute('style', 'visibility: hidden;');
    

    Per https://developer.mozilla.org/en-US/docs/Web/CSS/visibility#accessibilit..., this should be fine wrt accessibility.

    When I tagged this Needs accessibility review in #20 ~1.5 month ago, the solution was very different; now it's using CKEditor 5's built-in CSS properties 👍

  3. +++ b/core/modules/ckeditor5/js/ckeditor5.js
    @@ -370,9 +370,55 @@
    +          // user inputted value of number of rows. We attach this custom property
    

    "user inputted value" sounds a bit odd 🤓

  4. +++ b/core/modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5EditorHeightTest.js
    @@ -0,0 +1,172 @@
    +module.exports = {
    +  '@tags': ['core', 'ckeditor5'],
    

    😳 Holy cow, this test coverage is something else! 👏

  5. +++ b/core/modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5EditorHeightTest.js
    @@ -0,0 +1,172 @@
    +        .pause(500) // Wait for machine name to update.
    

    I'm afraid this is pretty much guaranteed to introduce random failures 😬

    We should wait for an explicit element to appear.

  6. +++ b/core/modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5EditorHeightTest.js
    @@ -0,0 +1,172 @@
    +        ) // Wait for Ck5 settings to be visible.
    +        .click('.ckeditor5-toolbar-button-sourceEditing') // Select the Source Editing button.
    

    🐛 Multiple comment formatting problems, plus "Ck5" should be "CKEditor 5".

  7. +++ b/core/modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5EditorHeightTest.js
    @@ -0,0 +1,172 @@
    +        .keys(browser.Keys.DOWN) // Hit the down arrow key to move it to the toolbar.
    +        .waitForElementVisible(
    +          '[href*=edit-editor-settings-plugins-ckeditor5-sourceediting]',
    +        ) // Wait for new source editing vertical tab to be present before continuing.
    

    These and a bunch of the other comments use very creative formatting that is implicitly revealing that our JS linting is failing to catch these? 🫣

mherchel’s picture

These and a bunch of the other comments use very creative formatting that is implicitly revealing that our JS linting is failing to catch these? 🫣

Yeah you can blame prettier for that! 🤣

Anyway, I moved around the comments and addressed all of the feedback above. Thank you for the review!

geek-merlin’s picture

Status: Needs review » Needs work

We're getting close!

I reviewed the code and can confirm that all the points from #68 have been addressed
... except some comment formatting in the JS test.

Still needs change record.

If we have both, i deem this RTBC.

mherchel’s picture

Which comment within the JS test? I'm pretty sure I addressed them all...

geek-merlin’s picture

I understood that in our standards the comments must be on their own line, whether php or js.
I may be wrong, but if i got that correctly, then comments like this are wrong:

+        .submitForm('input[type="submit"]') // Submit module form.
mherchel’s picture

Status: Needs work » Needs review

yeah, it's a little confusing IMHO.

Within https://www.drupal.org/docs/develop/standards/javascript/javascript-codi..., it states

If each line of a list needs a separate comment, comments MAY be placed on the same line and MAY be formatted to a uniform indent for readability.

I personally think this falls under that.

mherchel’s picture

ckrina’s picture

Status: Needs review » Reviewed & tested by the community

All concerns from #68 have been addressed and @geek-merlin's concerns have been answered too. Plus the extra pause(500) from #74 too, so marking this as RTBC.

mherchel’s picture

Assigning issue credits.

lauriii’s picture

Status: Reviewed & tested by the community » Needs review

I'm wondering if this a bug or feature because it doesn't look like CKEditor 4 isn't taking into account this configuration. Also, the UI explicitly states that "Text editors (like CKEditor) may override this setting". Should we adjust that to remove specific mention of CKEditor since after this issue CKEditor 5 does take that configuration into account. 🤔

lauriii’s picture

mherchel’s picture

Text updated to say "Text editors may override this setting."

andy-blum’s picture

Status: Needs review » Reviewed & tested by the community

Based on RTBC in #75 and a grueling review of the interdiff in #79, back to RTBC.

mherchel’s picture

Issue tags: -Needs change record

Change record created at https://www.drupal.org/node/3330010

Wim Leers’s picture

Issue tags: +String change in 10.1.0
FileSize
16.84 KB
19.04 KB

Code review

#72: That was also my understanding indeed.

But! core/tests/Drupal/Nightwatch/Tests/ajaxExecutionOrderTest.js and core/tests/Drupal/Nightwatch/Tests/claroAutocompleteTest.js apparently don't do this either. Perhaps it's a Nightwatch convention? 🤔 #73 answers that 👍

Change record review

I see two problems with the current change record though:

  1. it does not distinguish between CKEditor 4 and 5
  2. it claims With this change, Drupal will now show the proper amount of rows. → this is false, it's an estimation, and that's exactly why #2717599: Text editors do not respect <textarea rows>: make that clear in the formatted text field widgets modified the UI text. Note that rows is really a monospaced <textarea> concept, and only in that context can it work precisely. In the case of CKEditor 5, the line height of each line can be different — for example a subheading versus a paragraph, etc. The approximation algorithm Drupal applies to CKEditor 5 to make the rows setting apply approximately relies on a paragraph's line height.

Approach review

I'm in favor of this change after I first wanted to see CKEditor 4 support this upstream in #2717599: Text editors do not respect <textarea rows>: make that clear in the formatted text field widgets, which obviously never happened. Since #2877527: Make CKEditor (approximately) reflect the rows setting of a field has amassed a pretty high number of followers, and I've often been asked this question in person at Drupal events, I think this is a solid compromise 👍

Thanks for making this happen, @mherchel! RTBC +1

Screenshots — "typical before vs after"

#66 posted screenshots for a non-default rows setting. The default for text fields' widgets is rows=5, which looks like this

Before
After

Also added to the change record, since this will visually affect every Drupal site that is already using CKEditor 5.

mherchel’s picture

FileSize
11.86 KB
1.6 KB

Fixing a couple nits within the comments. Leaving to RTBC since only changing comments.

lauriii’s picture

Opened a follow-up to try to improve the wording of the description: #3330159: Potentially confusing wording in text area widget.

  • lauriii committed eddae137 on 10.1.x
    Issue #3241295 by mherchel, glynster, _utsavsharma, Emil Stoianov,...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs frontend framework manager review
FileSize
3.95 KB

Committed eddae13 and pushed to 10.1.x. Thanks!

nod_’s picture

should check that there is a row attribute with a value that is an actual number too.

lauriii’s picture

I did check https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea#attr-... to ensure that rows attribute only allows numbers. I also checked that the rows attribute should exist always, see \Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextareaWidget::formElement and config schema for field.widget.settings.text_textarea. Maybe we could do that as hardening in a follow-up?

geek-merlin’s picture

🎉 Thanks everyone for driving this home! So the ckeditorheight prorotype will stay for CKEditor4, but finally this is in core for CKEditor5.

hepabolu’s picture

Happy New Year everyone. Thanks for working this out. Could someone please create a 9.5 patch? I've tried to hack it together but failed. Applying the #44 doesn't show a minimum height that more or less matches the number of rows on my body field.

I'm trying to update to 9.5 and implement all the changes before upgrading to 10.x (preferably 10.1.0 or later).

mherchel’s picture

Sure thing! 9.5.x patch attached. Note this is not compatible with IE11.

hepabolu’s picture

Great! I can confirm the patch installs correctly and displays a minimum height of the textarea consistent with the number of rows. As a test I changed the number of rows from 8 to 5 and the height of the editor became smaller.
So here is at least one proof that the 9.5 patch works. Thanks a lot.

glynster’s picture

@hepabolu the bonus with #44 is the max-height. We find the max-height incredible useful whe you work with long form content. I am not sure where the seperate issue is, anyone know?

tgoeg’s picture

I'm in the middle of a big update so can't test this at the moment, maybe this use case outlined in #26 is now covered anyway.
But if max-height got removed as you imply then I think the row height setting is just a starting value and it still can grow further.

I don't think that's the primary functionality people need or the one expected if a row height can be set.
The auto-growing functionality is there, ootb, anyway. Don't people want to set this property when they need exact control of how big an editor field is, i.e. shorter because of the amount of editor boxes expected or even restricted to one line only?
Users can still manually expand the area if that's really needed (I guess?).

If really both is needed then maybe an additional checkbox "fixed height" would be useful?

geek-merlin’s picture

> We find the max-height incredible useful whe you work with long form content. I am not sure where the seperate issue is, anyone know?
Try this:
#3273755: CKEditor 5 should not grow to infinite height

Help apprediated in driving that home too!

glynster’s picture

@geek-merlin awesome thanks for pointing me in the right direction. Will jump over there too!

Wim Leers’s picture

@mherchel: since you're now the expert on this aspect of CKEditor 5, would you mind helping get #3273755: CKEditor 5 should not grow to infinite height across the finish line too? 🙏😊

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

claudiu.cristea’s picture

Version: 10.1.x-dev » 9.5.x-dev
Status: Closed (fixed) » Patch (to be ported)

This is a bug that affects also Drupal 9.5 and 9.5 is still long time supported (until December 2023). Not porting this to 9.5 is affecting the CKEditor 5 adoption. Most of the sites are now on Drupal 9.5 (or even 9.4), preparing for D10. Adopting CKEditor 5 is one of steps they want (true, not mandatory, but highly recommended) to solve before migrating to Drupal 10. But this is the kind of bug that wouldn't make CKEditor 5 module production ready.

Let's backport this, at least, to Drupal 9.5 to ease the CKE5 adoption. Luckily, @mherchel has already provided a patch in #91.

claudiu.cristea’s picture

claudiu.cristea’s picture

Wim Leers’s picture

OMG yes, and it hasn’t even been committed to 10.0.x either! 😳

Queued a 10.0.x test of #83.

Not sure why none of us thought of this 😅 I actually think that's because the "row" setting also never worked for CKEditor 4, so this is technically a feature … but for CKEditor 5, this helps overcome the "tiny initial size" problem, so in that sense it's a bug report.

So … let's see what core committers think 😊

(Also: no idea why I tagged it as a string change 🙈)

mherchel’s picture

So, while i agree that this should be going in 9.5/10.0, when I talked to @lauriii, his thoughts where this is a feature request (as opposed to bug). The reasoning was that the previous help text exempted CKEditor from having this behavior.

claudiu.cristea’s picture

@mherchel, I've backported in #101 but there's a Nightwatch failure that needs some attention. Sorry, but I've never worked w/ Nightwatch

Wim Leers’s picture

@mherchel thanks for confirming what I guessed in #102.

Up to committer's discretion then.

And actually, there is a string change:

+++ b/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWidget.php
@@ -25,7 +25,7 @@ class TextareaWidget extends StringTextareaWidget {
-    $element['rows']['#description'] = $this->t('Text editors (like CKEditor) may override this setting.');
+    $element['rows']['#description'] = $this->t('Text editors may override this setting.');

This was just omitted from @mherchel's 9.5 backport in #91, which led me to the wrong conclusion. And that is actually a reason that makes backporting this even less likely… 😅

vikas shishodia’s picture

@claudiucristea I applied patch #101 with Drupal 9.5.7, ckeditor5 and it worked fine. Only there is one confusion, after applying this patch if we have set row as 5 in manage form display for the field then it is only showing as 2 on editor.
If we set 6 it is showing 2 rows.
If we set 7 it is showing 3 rows.
If we set 8 it is showing 3 rows.
If we set 9 it is showing 4 rows.
If we set 10 it is showing 4 rows.
and so on....

So is there any reason behind this or this is a bug?

mandclu’s picture

naveenvalecha’s picture

FileSize
4.19 KB

Here's the patch which I rolled for 10.0.9 for a project

catch’s picture

Version: 9.5.x-dev » 10.1.x-dev
Status: Patch (to be ported) » Fixed

We're approaching the 10.1.0 release candidate and there's a fair amount of logic here plus a string change, so I think we should leave this fixed in 10.1.0. It is useful to have the backport patch from #108 for people that want to run it on 10.0.x

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

seeduardo’s picture

FileSize
32.98 KB

I can confirm that the patch at #101 is working correctly for me on Drupal 9.5.10, without the issues mentioned in #106 - thanks for that, and see below when Body field set to 5 rows, for an example:

Body has correct 5 rows

genebobmiller’s picture

In a recent 10.1.2 install I am seeing the field widget row settings respected on the Body field but not the Summary field.
Is that expected?

puidu’s picture

Patch at #101 works fine but only if the element is visible in the viewport, otherwise the calculated height is not correct.
It seems that the cause is that the clientHeight method applied to the 'p' html tag element created to calculate the height of the text area. If the textarea is not in the viewport, the calculated height for 'p' will be 0.
Pretty sure there is a much better solution (reason why I'm not posting a patch), but for now I solved replacing
var height = element.clientHeight
with
var height = element.clientHeight > 0 ? element.clientHeight : 16;
(16px is the most common height for p)
into core/modules/ckeditor5/js/ckeditor5.js

edmund.dunn’s picture

FileSize
872 bytes

I went ahead and created a patch from the work @puidu did in #113. That worked for us; we have several instances where the initial render of one of the ckeditor5 instances was out of the viewport, and the height when it was revealed was set to 65px. Changing it to 24 gets us close to the 180pc height all of our other ckeditor instances have.

Mysdiir’s picture

Can confirm that patch #101 works for D9.5.11. :)
Thx for your work :)