Problem/Motivation
When there are many items in the toolbar of CKEditor5, the buttons are relegated into a drop-down menu. However, depending on how many items there are, this can get clipped in Drupal's off-canvas:

Steps to reproduce
- Enable the Layout Builder, Node and Block Content modules.
- Create a block type that has a formatted text field.
- Create a CKEditor5 editor configuration with many buttons.
- Create a node type and enable the layout builder.
- Edit the layout.
- Hit the Add block button to an existing section to bring out the off-canvas dialog.
- Hit Create a custom block.
- (If there are multiple block types on the site) Choose the block type that has a formatted text field.
- Open the overflow menu drop-down, see that is is clipped and partially unusable.
Proposed resolution
Change the value of --ck-toolbar-dropdown-max-width variable to be relative to the width of the editor instance.
This can be achieved with CSS container queries as follows.
.ck.ck-editor {
container-type: inline-size;
container-name: ck-editor;
}
@container ck-editor (width > 0) {
.ck-dropdown__panel {
--ck-toolbar-dropdown-max-width: 90cqw;
}
}
Remaining tasks
Fix.- Review.
- Commit.
User interface changes
The dropdown width will always be less than the editor width, ensuring that it never gets clipped if the editor is in a div with overflow: hidden; like off-canvas.
Before:


After:


API changes
None.
Data model changes
None.
Release notes snippet
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | 3328095-nr-bot.txt | 664 bytes | needs-review-queue-bot |
| #30 | 3328095-mr8096.patch | 773 bytes | vasantha deepika |
| #24 | 3328095-24.patch | 2.64 KB | redwan jamous |
| #24 | after-source.png | 128.12 KB | redwan jamous |
| #24 | after-wysiwyg.png | 128.94 KB | redwan jamous |
Issue fork drupal-3328095
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
wim leersThanks for the clear issue! 👍😊🙏
How does this behave with CKEditor 4?
(Asking to determine if this is a regression or not.)
Comment #3
wongjn commentedAs far as I am aware, CKEditor 4 had no such overflow drop-down menu – the toolbar buttons would wrap to new lines (screenshot taken from their documentation site):
Comment #4
wongjn commentedAnd indeed, CKEditor 4 in the off-canvas in Drupal 9 does wrap instead of exhibit an overflow menu drop-down:
Comment #5
wim leersSo CKEditor 4 was clearly not rendering in a nice way either. Because it was never designed for narrow viewports.
CKEditor 5 was designed to work well on narrow viewports. 😊 We just need to figure out if the problem is:
I'd suspect it's the first, so let's try to rule that out (see https://ckeditor.com/docs/ckeditor5/latest/features/toolbar/toolbar.html...), so could you please try the attached patch and report back? 🙏
Comment #6
wongjn commentedMade no difference unfortunately.
I believe the discrepancy here could be that actually the viewport is quite wide (these screenshots were taken on a maximised browser window of a 1920×1080 screen) but the area that the editor is in is quite narrow.
In case this helps at all, here is temporary JavaScript code I concocted to adjust the overflow menu size:
Comment #7
wim leers#6: that sounds very plausible! https://caniuse.com/css-container-queries only started shipping a few months ago…
Comment #9
ravi kant commentedThe solution of remove dropdown of extra tools in CKEditor is providing by CKEditor and it is "Button divider". It will break the CKEditor toolbar in next line.
How to use?
Comment #10
ravi kant commentedComment #11
smustgrave commentedMoving to active as there is nothing to review
#9 seems to describe building a text editor to be narrow and only have a few buttons each line vs responsive, which I believe was the discussion before.
Correct me if I'm wrong.
Comment #12
smustgrave commentedtried #6 but didn't seem to work for me.
Comment #14
smustgrave commentedFound the css causing the issue. It's from ckeditor5. It's applying width: max-content.
I'm overriding that and seems to work but sure it's not ideal. Thoughts?
Comment #15
jwilson3I had experienced something like this on a site with Layout Builder + CKEditor 4 and my workaround was to just widen the LB sidebar flyout. The edge of the flyout is drag-enabled in some contexts, (but I did notice unfortunately not all contexts, though I cannot now remember where it was set to a fixed width). IMHO, the offCanvas for LB should be wider on larger screens. Maybe a follow-up?
Also, I don't see a huge drawback in overriding width: max-content on the wrapper as long as it is in the correct context and solves the problem.
Comment #16
bkosborneI think this is a legit bug, but the workaround to get this behaving as it did in CKE4 is mentioned in #9. Just add the "wrapping" button divider anywhere in the toolbar (even as the last item). That will prevent CKE5 from trying to render everything on one completely.
Comment #17
randalv commentedThanks to #9 and #16, I can confirm that adding the "wrap"-item even as the last item on the bar is a solid workaround until a permanent fix can be provided.
It wraps the excessive items neatly on a second row (as was the behaviour in CKEditor4 if I'm not mistaken).
Comment #20
redwan jamous commentedCreated a MR that fixes the issue using CSS container queries.
The
--ck-toolbar-dropdown-max-widthvariable will be set to 90% of the editor's width instead of 60% of the viewport's width.Before fix:

After fix:

Adding a patch file to use with composer...
Comment #23
smustgrave commentedIf a new solution is being proposed issue summary should match.
Also before/after screenshots need to be added to the issue summary.
Comment #24
redwan jamous commentedThank you, @smustgrave! I'm updating the issue summary...
Unfortunately, the previous fix doesn't work well while source editing mode in CKEditor is active.
To overcome the issue, the container can be the parent element (
.ck.ck-editor) instead of.ck.ck-editor__top.However, changing the css from:
To:
isn't enough because off-canvas reset (
core/misc/dialog/off-canvas/css/reset.pcss.css) is applyingall: revert;with higher specificity which will overwrite ourcontainer-typeandcontainer-name.Adding
.ck-editorto the list of elements excluded from the off-canvas reset rules would fix the issue, but I'm not sure about this change.We currently have the following selector in off-canvas reset:
#drupal-off-canvas-wrapper *:where(:not(svg, svg *, .ck-reset *, [data-drupal-ck-style-fence] *, .ui-resizable-handle))We're excluding all children elements of
.ck-resetbut not.ck-resetitself (unlike svg).The new proposed selector:
#drupal-off-canvas-wrapper *:where(:not(svg, svg *, .ck-reset, .ck-reset *, [data-drupal-ck-style-fence] *, .ui-resizable-handle))Also, CSS linting checks are failing because of the
cqwunit, so I will be creating a separate issue to add container query units to the allowed units since they're now supported in all major browsers.Comment #25
smustgrave commentedThanks for updating. Appears to have some failures in MR.
Comment #26
specky_rum commentedPatch in #24 fixes this for me. Had the same problem but caused by the editor being setup within vertical tabs on the Claro theme which prevents overflow.
Comment #27
redwan jamous commentedTests are passing locally. Not sure what the problem is.
Comment #29
vasantha deepika commentedLet me check the pipeline issue and try to fix it.
This MR only includes CSS changes, but the failure seems to be caused by a JS functional test (JSWebAssertTest), which appears to be unrelated to this update.
I will investigate further and re-run the pipeline if needed. Will share findings shortly.
Additionally, I have increased the dropdown visibility by adjusting the --ck-toolbar-dropdown-max-width value from 90 to 95 to ensure the CKEditor 5 toolbar dropdown displays correctly.
Comment #30
vasantha deepika commentedThe MR !8096 seems fine, but the pipeline is failing due to test-related files.
I'm attaching a patch generated from the MR [3328095-mr8096.patch] in case anyone needs it to proceed without being blocked, until the MR is merged.
Comment #31
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.