-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Insertion point bar: hide onBlur and onMouseLeave #36798
Conversation
Size Change: +12 B (0%) Total Size: 1.1 MB
ℹ️ View Unchanged
|
74bd330
to
240d5de
Compare
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.
Gave it another spin, and in all my testing I saw no downsides to this one.
The code looks minimal and good. I'd encourage just a quick sanity check from another dev, but honestly this feels good enough to land.
@@ -294,6 +300,8 @@ function InsertionPointPopover( { | |||
// Forces a remount of the popover when its position changes | |||
// This makes sure the popover doesn't animate from its previous position. | |||
key={ nextClientId + '--' + rootClientId } | |||
onFocusOutside={ maybeHideInserterPoint } | |||
onMouseLeave={ maybeHideInserterPoint } | |||
> | |||
<motion.div |
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.
I've started looking at this and I'm not familiar with this code, but I was wondering if you have search for a solution from motion maybe something like onHoverEnd={ maybeHideInserterPoint }
in this motion.div?
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.
I was wondering if you have search for a solution from motion maybe something like onHoverEnd={ maybeHideInserterPoint } in this motion.div?
Thanks for looking!
I tried it out and I don't see any difference in behaviour, so I don't see any implementation issues with it.
Was there a specific reason why we should prefer motion's eventhandler?
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.
Was there a specific reason why we should prefer motion's eventhandler?
Oh, I did find one advantage, aside from the fact that Popover
doesn't specifically define an onMouseLeave
event: we can perform an equality check on the even target and the current ref to make sure the event is occurring on the motion div.
I've pushed that change since I couldn't detect any noticeable divergence in behaviour.
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.
Thanks for working on this Ramon! It would be great if @ellatrix shared her thoughts here as she has worked a lot with these parts. Should this be better handled here: https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/block-list/use-in-between-inserter.js#L15?
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.
Tried this and I agree is a big improvement. I'm not familiar with the code, so good to get @ellatrix's input if it makes sense in a difference place. Either way this should land once that's done.
Thanks for testing, everyone!
Yes, I'm also a newbie in this area of the code so would be interested to hear if there's a better way. I couldn't see how we could attach event to the inserter in that hook. |
…over, and also the mouse leaves the horizontal line. Only hiding when the block inserter panel is not open
There seems to be no noticeable difference in behaviour, only that the Popover component doesn't specifically define an `onMouseLeave`. Also, we can more easily perform a check against the ref and event target.
240d5de
to
9ebdd37
Compare
I removed the There is an edge case that this PR does not address: the inserter persists when you click the plus icon and drag your mouse away from it. This is because there's an exisiting onFocus callback on the motion div that sets |
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.
LGTM, thanks Ramon! Changes are minimal and make for a way better experience.
There is an edge case that this PR does not address: the inserter persists when you click the plus icon and drag your mouse away from it.
I think we can address this in a follow up, as it's already in trunk. Maybe this should be handled in useInBetweenInserter
as we are only listening to mousemove
event and we could add logic for detecting the dragging.
Possibly, in some way, resolves #35536
Also resolves #36882
Description
This PR hides the inserter point via the
hideInsertionPoint
action when the horizontal inserter bar loses focus, or when the mouse leaves.hideInsertionPoint
will not fire when the block inserter panel is open.We might not have covered all cases documented in #35536, and there is no timeout, but it might help to avoid some of the concerns with the persistent inserter bar.
Try it out today!
How has this been tested?
Take a look at the various scenarios over at #35536
With the right mouse artistry you might find that the bar persists, but, at least in my testing, it doesn't persist as often with these changes.
Checklist:
*.native.js
files for terms that need renaming or removal).