-
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
Technical Feedback for showing hovered block labels in an external component. #25469
Comments
At first glance, I'd probably go with solution 1 personally. I believe we already track (or tracked) block hovering internally in the BlockListBlock component in an internal state, I'm fine with it in the block-editor state. About the block inserter disruption, I wonder if this is related to the use of React events instead of DOM events (event bubbling is distrupted), so I'd consider trying event handlers using the "ref" in the BlockWrapper component. |
Could solution 1 be augmented so that blocks can opt into this? Unrelated to any particular approach above - will this work for nested template parts? Do we have an easy way to determine the top level one with the above solutions? |
maybe the blocks using controlled inner blocks. cc @noahtallen |
In the above approaches the array of clientIds is ordered. So the template part inside another template part would be closer to the front of the list. That does remind me of a similar problem we are trying to solve regarding how to tell if the selected block belongs to a template part. 🤔 |
There are definitely ways to make it opt in. However, if we are putting |
The inner block controller thing is one way to check a block to see if it is a parent template part. I'm not sure we actually need that in this case
I imagine we could also do it the other way around too (e.g. In my opinion, I'd think that in the proposed designs, the "current" template part block would be active in the header area, which would be the most specific one (rather than the root one).
(i agree with Addie, and had already written this up before that comment :P) Theoretically yes, but I don't know if it makes a big difference performance-wise? It seems to me that if we want to implement a block-editor-level store for the currently hovered block(s), then it should just work for all blocks. For example, it's not like we have to opt-in to |
It doesn't seem to solve it (#25348 (comment)) but there are some other ways we could get around it. |
That makes sense. It was listed in the cons section of solution 1 and I tried to suggest a possible way to deal with it. But it sounds like it's not really a con after all, more like a feature/pro. :) |
Closing this as we have been moving forward with developing a solution on - #25348 - we can always come back to other approaches in the future if necessary. |
In working towards the designs suggested for adding Template and Template Part names in the top bar of the Site Editor (#25085), one challenge we face is determining how to communicate when a Template Part is hovered to the new component so that it may display the name of the hovered template part.
We have several ideas (and corresponding rough (but working) draft PRs) regarding how to accomplish this, but are unsure which solution may be the most appropriate for Gutenberg in general. Below, I will describe the various approaches, their pros and cons, and provide links to the rough draft PRs that give a rough idea of how these work in action. My hope in exposing these options is to receive some feedback, context, or other ideas for what may be the most appropriate solution to pursue further to enable this functionality.
A summary of the three approaches:
Solution 1 - Add listeners to all blocks and a
hoveredBlocks
reducer to thecore/block-editor
store (#25348).Implementation:
Pros:
core/block-editor
store that can be used for other purposes if necessary.Cons:
Solution 2 - Add listeners to only the blocks of interest and using
core/edit-site
store (#25382).Implementation:
core/edit-site
store for our new component (since it is only currently intended for the Site Editor).Pros:
Cons:
Solution 3 - Track mouse movement and parse elements under the cursor (#25423).
Implementation:
elementsFromPoint
to retrieve the elements under the cursor.Pros:
elementsFromPoint
solves the issue with the interfering inserter. This sounds small, but in practice feels much better.Cons:
I do like how approach 3 behaves with the inserter, as well as its simplicity. However, I am still slightly uneasy about it firing every mousemove.
What are other thoughts on which approach may make the most sense? Perhaps other ideas? Or hybrids of the above - (such as creating the hoveredBlock store described in approach 1, but still using
elementsFromPoint
when that changes to behave well with the inserter but run less often than mouse move)?Thank you for taking the time to read through this wall of text and considering our options!
@youknowriad @mcsf any thoughts?
@vindl @noahtallen @jeyip @Copons @david-szabo97
The text was updated successfully, but these errors were encountered: