question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Margins are not collapsed because of `slate-data-spacer`

See original GitHub issue

Do you want to request a feature or report a bug?

  • Bug

Example to reproduce : https://jsfiddle.net/BanB4n/gszke21n/14/ Informations: MacOS, Google Chrome, Slate 0.33

What’s the current behavior?

capture d ecran 2018-05-24 a 15 49 10

The data-slate-spacer div prevents the collapsing of margin.

What’s the expected behavior?

capture d ecran 2018-05-24 a 15 49 28

At GitBook, we fixed this by adding position: absolute to the data-slate-spacer element. But we are not confident about this solution, since we are not sure to understand the purpose of this spacer.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
freeplantcommented, Aug 30, 2018

In our project, we render Markdown documents using Slate. The images in a document are rendered as inline nodes. With this change (adding position: 'absolute'), when an inline image is clicked, the view will jump to an incorrect scroll position.

In scrollToSelection() https://github.com/ianstormtaylor/slate/blob/1923888af1b07b6c21ea20b0a9f054a5cbb27654/packages/slate-react/src/utils/scroll-to-selection.js#L74

let cursorRect = range.getBoundingClientRect()

returns incorrect cursorRect.

Hope a better solution can be found.

0reactions
sampokcommented, Oct 1, 2018

I have the editor in a scrolling div and experienced the same problem as @freeplant, except that it didn’t seem to matter whether the image was inline or block.

In my case the solution was to set “position: relative” to the editor area (or an immediate wrapper). Without it absolute position was off and the view jumped when focusing on images.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mastering margin collapsing - CSS: Cascading Style Sheets
Margin collapsing occurs in three basic cases: Adjacent siblings. The margins of adjacent siblings are collapsed (except when the latter sibling ...
Read more >
Why are margins not collapsing? - css - Stack Overflow
Flex items' margins won't collapse. When flex items wrap, they create their own row, and the individual margins on the flex items won't ......
Read more >
What is Margin Collapse in CSS? And How to Avoid It
Margin collapse can cause unexpected behaviors in your layout. You'll likely see applied spacing that doesn't seem to match up with what you ......
Read more >
The Rules of Margin Collapse - Josh W Comeau
You can think of padding/border as a sort of wall; if it sits between two margins, they can't collapse, because there's a wall...
Read more >
What You Should Know About Collapsing Margins | CSS-Tricks
The bartender asks if he should be cut off and the spacing replies, “No, I'm just a collapsed margin.” Sorry, dumb joke.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found