-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try position sticky for undocking toolbars #660
Conversation
One consideration is that browser support isn't that great, so may need a polyfill, or JS fallback solution for Edge. The general idea looks great though. |
It doesn't need a polyfill I think. If it works, great, if it doesn't, it works as before. |
z-index: 1; | ||
margin-top: -56px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's 56px
? Probably good to comment which selectors this belongs to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, was looking for a way to replace that with variables, but couldn't immediately put it together and I had to relocate. Definitely will, though.
Noting for myself that I need to adjust some margins for when the toolbar is inside a heading block, as the heading block recently moved to using paddings. |
Can we consider applying |
We can, but that won't solve the However I'm confident I can find another full-width solution that works with this. |
It looks also very useful for other blocks like big images and galleries. |
I pushed a bunch of changes to this branch, which fixes every issue I could find. This includes moving to using this It's working really well. Here's a video: https://cloudup.com/cw53qxfqjLa That being said, I would imagine that there could be a bunch of side-effects to moving the max-width from the containing element and down into each block. And so aside from a whole bunch of 👀 on this, I will do some testing in various browsers. But right at this chrono-juncture, this feels like the right thing for us to do. |
This is working great! I wonder if it might be better to add some margin under the toolbar, so that it will unstick sooner and not stick when the block is smaller than that margin. |
Here's what I mean: .editor-visual-editor__block-controls {
position: sticky;
margin-bottom: $item-spacing + 100px;
/* ... */
}
.editor-visual-editor__block-controls + div {
margin-top: -100px;
} This trick creates a 100px "buffer".
100px is just an example, it can probably be a bit more. |
Ooh I love that! Super clever. Going with 100 for now, we can always tune. |
Okay, rebased, added your fix, @iseulde, and included a collapsing margins fix. Actually there's an issue with the collapsing margin fix, I want to find a better one. Give me a sec. |
Okay I'm actually ready for a final pair of 👀 now. The last commit uses a clearfix to prevent collapsing margins. To clarify a bit: position sticky requires us to use the Using margins for positioning the toolbar is fine, though — the math is pretty simple and using a negative margin to push the toolbar up, and a positive margin to compensate for the void means it works. The only problem is when the block itself uses a top margin to position itself inside the block boundary. Embed and Lists do this at the moment (they shouldn't, but we can't prevent 3rd party blocks from doing it), we get _collapsing margins. Here's an ascii drawing:
In the above illustration, the blocks top margin collapses, causing a jump when you select the block. The clearfix prevents that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really cool effect when it works. I'm having a few issues though:
https://cloudup.com/c68mv7eOVnU
- The sticky effect only goes about 2/3 down the block
- The sticky effect only works for the first text block, but not adjacent ones
(These might be the same issue surfaced in two different ways)
It doesn't need a polyfill I think. If it works, great, if it doesn't, it works as before.
Have we verified that this doesn't fail spectacularly in browsers where sticky isn't supported?
editor/layout/style.scss
Outdated
@@ -1,3 +1,3 @@ | |||
.editor-layout__content { | |||
overflow: hidden; | |||
//overflow: hidden; // temp commented out for position sticky |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be removing this?
This should be seen as a progressive enhancement. Position sticky allows us to have relatively positioned toolbars right until the content starts scrolling out of view, at which point it starts behaving as position: fixed. This is exactly what we want for very long editor blocks. There's no reason we can't try this and get a feel for it. This is not yet fully polished, but please have a look and a test and a feel, and let's discuss.
Will revisit if becomes necessary.
Still a work in progress.
It wasn't really before, due to the mover on the left.
This is working really well. But we need to test for side-effects. If we can use this, it really simplifies the responsive centering math.
Also adjust the bottom block offset at which the toolbar unsticks.
Removed the layout stylesheet as it's now empty.
Those were both the same issue, and resulting from Ella's tip here: #660 (comment) — basically we are adding a bottom margin to the block, so when you only see n pixels of the block, it stops being fixed position. I reduced this to 50px, and open to removing it entirely, though I do like it. I also rebased. Good for a final look? Thanks for the review! |
Forgot to answer this one:
I've tested this codepen: https://codepen.io/joen/pen/wdqYLO — the behavior in unsupported browsers is quite nice, it simply behaves as though the entire |
I must not have been paying attention when I overlooked the past few comments about having a buffer zone for the toolbar 😄 Personally I'm not sure why we need it. And if my uninformed commentary is any indication, it felt like a bug to me. |
I don't have a strong opinion on this. I just don't see why it should stick until the end until it can no longer be used, and why it should be enabled on tiny blocks. |
Did the toolbar previously end up going past the bottom of the block? I think it'd make sense to have it stop when the toolbar's bottom reaches the block's bottom. |
I adjusted this bottom buffer zone to be about the same as a single line of text. I think this works well: I think it's good to have a buffer zone — if we don't have any, it'll stop when the bottom of the toolbar touches the very edge of the block boundary, which also looks buggy. Though I totally see Andrews point that it felt like a bug when it was 100px (even though I also did like that). Since it's now at about 1 lineheights worth of buffer zone, I think it might be worth merging in and getting a feel for it. If we decide to go lower, we it's easy to edit here: d59848c Final 👍 👍? |
I like this 👍 |
This should be seen as a progressive enhancement.
Position sticky allows us to have relatively positioned toolbars right until the content starts scrolling out of view, at which point it starts behaving as position: fixed. This is exactly what we want for very long editor blocks. There's no reason we can't try this and get a feel for it.
Note: because
position: sticky;
is still experimental, there are some quirks. Likeposition: fixed;
, it doesn't work if a parent container has atransform
applied. In addition, it doesn't work if a parent hasoverflow: hidden;
, which incidentally means if we want this we'll need a different approach to full-width images (which I volunteer to fix in that case).This is not yet fully polished, but please have a look and a test and a feel, and let's discuss.
Video:
https://cloudup.com/che4XEHEKk9