-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Content only block inspector controls: add block selection and keyboard navigation #73221
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
Content only block inspector controls: add block selection and keyboard navigation #73221
Conversation
- Pass paneId to tools panel items so that reset works. - set shownByDefault consistently.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +70 B (0%) Total Size: 2.41 MB
ℹ️ View Unchanged
|
| attributeValues={ attributeValues } | ||
| updateAttributes={ ( attributes ) => | ||
| updateBlockAttributes( clientId, attributes ) | ||
| const isSelected = isBlockSelected( clientId ); |
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.
Bit of a nit, but this line stands out to me a little bit because it's not within a useSelect where we'd usually expect. Is that because you wanted to call it after the check for whether there's a ControlComponent? If so, one option could be to move the check for controls[ control.type ] out of this function and to the fields?.map in BlockFields instead, then the check to see if the block is selected could be in the useSelect?
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.
Nice spotting. I was just amazed it worked, and checked it in 😄 Lemme see
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.
Good idea, i'll do the check in the map 👍🏻
| <div | ||
| className="block-editor-content-only-controls__item-wrapper" | ||
| onClick={ handleClick } | ||
| onFocusCapture={ handleFocusCapture } |
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.
Oh clever! When I was looking at the DataForm PR I'd gone more complex and had the individual components have to handle this, but this is a bit more clever 👍
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.
Maybe it's still a hack, but doesn't look out of place right now 😄
andrewserong
left a comment
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! I like that it changes which block is selected, but the spotlighting feels possibly a little too aggressive for my own tastes. Quite possibly a design decision, though! Here's how it's looking for me:
2025-11-13.15.31.40.mp4
A couple of thoughts:
- While spotlighting makes it easier to see what you're interacting with, it can be harder to get a quick view of how it looks "normally" again. If the field is blurred, I'd expect spotlighting to go back to what it was, which is to say, switch it off. So, clicking anywhere else within the sidebar, opening / closing panels, etc should all switch off the spotlight mode IMO. That might make it feel a bit less intrusive to me.
- I notice that if I select a field using just the right-hand controls, then the rich text controls aren't visible in the canvas until I click into the canvas. There could be something going on with selection checks that causes this, but I'm not sure.
Overall, though, I like that this is guided us toward a clearer way of navigating around, though, and attempting to deal with the potential confusion of the sidebar vs editor canvas 👍
Would it be worth trying to land the other PR first, or are you hoping to get this change rolled into it first?
| <div | ||
| className="block-editor-content-only-controls__item-wrapper" | ||
| onClick={ handleClick } | ||
| onFocusCapture={ handleFocusCapture } |
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.
Actually, this wrapper doesn't play nicely with the ToolsPanelItem — when an item isn't visible, the tools panel item will render null, but this additional div means that if items are not visible, they still get rendered as an empty div, which results in this bit being extended visually:
We might find another way of handling this if/when we look switching over to DataForm. I.e. in #73186 I was looking at the idea of using an ad hoc DropdownMenu for controlling visibility rather than depending on ToolsPanel. It's a bit of a throwaway experimental PR, but just as an idea for how we might handle this sort of thing later on.
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.
Sounds good. Let's leave this PR as a demonstration then 👍🏻
Totally, I was just playing around. Let's leave this as a demo. Thank you for testing! |
|
Connected to this, we should also remove outlines on hover: Sections: Remove hover outlines |
|
closing this as we move to data forms #73261 |
What?
This PR builds on #71730 and (in a hacky way) adds navigation between component controls, and toggles the item in the canvas.
This PR is not perfect, but it enhances the fields, which is behind an experiment.
Why?
For large patterns, editing using the inspector tools can be confusing you might be editing a block you cannot see. At the very least it breaks the WYSIWYG pattern.
Also keyboard navigation between fields isn't working.
How?
Wrapping the content controls in a div and adding events that call
toggleBlockSpotlightTesting Instructions
Insert a few patterns/template parts and check that you can edit the fields still, and the block that you're editing is highlighted and visible.
For me it doesn't work ALL the time for some reason, but it's an improvement.
Screenshots or screencast
2025-11-13.13.40.46.mp4