ckeditor5
ckeditor5 copied to clipboard
Fix bottom margin jump on focus
Suggested merge commit message (convention)
Fix: Bottom margin jumps on focus. Closes #15859
Additional information
This fixes a bug where the bottom padding of the editor will jump on focus, because the .ck-fake-selection-container
element is added, which is fixed-positioned, but drops the margin-bottom
styling from whatever was the :last-child
.
It uses the :has
selector, which is widely available now.
Related issues:
- #847
- #9825
@brandonkelly could you provide some visual (video would be great) of the before and after, so that we are 100% on the same page. cc @oleq @pszczesniak
Sure!
Here’s a CKEditor field that ends with a <figure>
, which normally has a bottom margin of .9em
, except if it’s the :last-child
where it will be set to var(--ck-spacing-large)
.
https://github.com/ckeditor/ckeditor5/assets/47792/bf0f1cad-a959-46b6-9057-bc94f38a6d61
It’s subtle, but if you look closely you’ll see the editor shrinks by a few pixels when focused due to the difference between those margins.
With my PR, it no longer matters what elements’ normal margins are. They will get the same :last-child
bottom margin, whether they are actually the last child, or if they are directly followed by the .ck-fake-selection-container
element which is the actual last child.
https://github.com/ckeditor/ckeditor5/assets/47792/baaf40be-200e-4b65-8219-6c03f81ed95b
@vokiel could you verify CLA?
Confirmed. Proper status set.
The PR looks good to me (both the functionality and the code). Can we run it by the QA team @Witoso just to stay on the safe side?
Yep, we can do it.
@ckeditor/qa-team Can you take a look at this PR, please?
Sure, we will take a look at this 👍
Bottom margin jumps with certain styles applied
Steps
- Open all-features.html
- Set editor data to
<figure class="image"><img src="sample.jpg" alt="bar"><figcaption>Caption</figcaption></figure><h2 class="document-title">test</h2>
- Shift the focus between the image and the heading
Result
https://github.com/ckeditor/ckeditor5/assets/132071257/c05e2863-30bc-4495-bcac-6c15e8519f90
Alternative scenario
- Open all-features.html
- Set editor data to
<figure class="image"><img src="sample.jpg" alt="bar"><figcaption>Caption</figcaption></figure><p class="info-box">test</p>
- Shift the focus between the image and the paragraph
Result
https://github.com/ckeditor/ckeditor5/assets/132071257/8fa5270f-692b-4cf0-9e9b-0ce03f310951
Additional info
It's a regression - doesn't reproduce on master
We've tested the PR with @marcelmroz and @kubaklatt and have found one regression that it introduces, which occurs when certain styles are used and is reported above. Besides that, the fix looks good and resolves the initial issue 👍