ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

Fix bottom margin jump on focus

Open brandonkelly opened this issue 1 year ago • 8 comments

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 avatar Feb 04 '24 22:02 brandonkelly

@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

Witoso avatar Feb 05 '24 08:02 Witoso

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

brandonkelly avatar Feb 05 '24 13:02 brandonkelly

@vokiel could you verify CLA?

Witoso avatar Feb 06 '24 08:02 Witoso

Confirmed. Proper status set.

vokiel avatar Feb 06 '24 11:02 vokiel

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?

oleq avatar Feb 14 '24 12:02 oleq

Yep, we can do it.

Witoso avatar Feb 15 '24 08:02 Witoso

@ckeditor/qa-team Can you take a look at this PR, please?

oleq avatar Feb 15 '24 09:02 oleq

Sure, we will take a look at this 👍

dufipl avatar Feb 20 '24 10:02 dufipl

Bottom margin jumps with certain styles applied

Steps

  1. Open all-features.html
  2. Set editor data to <figure class="image"><img src="sample.jpg" alt="bar"><figcaption>Caption</figcaption></figure><h2 class="document-title">test</h2>
  3. Shift the focus between the image and the heading

Result

https://github.com/ckeditor/ckeditor5/assets/132071257/c05e2863-30bc-4495-bcac-6c15e8519f90

Alternative scenario

  1. Open all-features.html
  2. Set editor data to <figure class="image"><img src="sample.jpg" alt="bar"><figcaption>Caption</figcaption></figure><p class="info-box">test</p>
  3. 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

charlttsie avatar Feb 27 '24 10:02 charlttsie

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 👍

charlttsie avatar Feb 29 '24 15:02 charlttsie