-
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
feat: Show sidebar in HTML edit mode for blocks #8969
Conversation
Just a question: A block author might have selection dependent controls in the inspector (imagine a "bold" button in the inspector) and in that case it will break I guess? I think that's the reason we hide the toolbar. Granted that this use-case is probably less important but conceptually speaking, there's no difference between |
That's a good question, I'll look through blocks that do that. Do you know of any blocks that do that? |
@tofumatt I don't think we have any in Core blocks. |
So should we maybe have an option/API that explicitly disables blocks from having inspector controls appear?
|
Yes, or maybe. An option would be to not render it :). If you're in the global code mode, there's no toolbar/inspector. 🤷♂️ At least that has my vote. |
If there aren't any controls that modify only selected content in the inspector I don't see the issue, but I suppose if that's a thing we:
then this is a dangerous idea to implement, yeah. The issue didn't really delve into the edge cases around it. For what it's worth I found it, even in my testing, to be a nice UX to see the HTML instantly update from the inspector and to see what each control did to the HTML. That said, it's a fairly edge case usage. |
It seems like blocks that treat inline elements would all somehow touch the Editable no? Can we detect this in any way? |
IMO anything in the sidebar should affect the block as a whole, not an active selection. I don't know that we need to detect this, but it could be something worth documenting. |
That makes sense to me, and certainly feels like the implication made by the way all of the core blocks have been designed. |
If we document that and someone builds it regardless, presumably they can then respond to feedback when their users report a thing not working. |
@jasmussen @tofumatt I know of one plugin that uses the inspector controls for inline formatting: https://wordpress.org/plugins/advanced-gutenberg/ This plugin uses the inspector for single-cell formatting in the Advanced Table block. I would not say it is the most intuitive experience, but that is how they implemented it. |
We need a decision to get this in for 3.6 or not. It could be just a documentation addition. |
Sounds like there's agreement that it's not the right way to do things, so I'm happy to document that… seems like it should go in https://github.com/WordPress/gutenberg/blob/master/docs/blocks/block-controls-toolbars-and-inspector.md, but should it be anywhere else? |
@tofumatt That document appears a fine place. If we had documentation here, I'd also make mention of it: |
Okay, I've added some documentation to both the component (sparse) and to the existing guidelines on creating a block. |
|
||
## Inspector | ||
|
||
While the toolbar area is useful for displaying controls to toggle attributes of a block, sometimes you will find that you need more screen space for form fields. The inspector region is shown in place of the post settings sidebar when a block is selected. | ||
<img src="https://raw.githubusercontent.com/WordPress/gutenberg/try/4413-format-options-html/docs/blocks/inspector.png" with="281" height="527" alt="inspector"> |
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 have a feeling that this link will break if / when we delete the branch (standard practice).
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.
It will, but I wanted it in here until we merged so people could see it 😄
I plan to change it to master before merge, but you're right: I should've mentioned it 😄
// HTML mode. This allows us to render all of the ancillary pieces | ||
// (InspectorControls, etc.) which are inside `BlockEdit` but not | ||
// `BlockHTML`, even in HTML mode. | ||
const BlockEditWrapper = mode === 'visual' ? Fragment : |
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 think we should be consistent with ternary fragment placements: Either all on one line, or Fragment and 'div'
separately on their own lines.
toggleSelection={ this.props.toggleSelection } | ||
/> | ||
{ isValid && ( | ||
<BlockEditWrapper style={ mode === 'visual' ? null : { display: 'none' } }> |
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.
We duplicate this condition from before. Makes me wonder if there's another way we could apply the wrapper to keep the logic contained:
Component:
function BlockEditWrapper( { isVisual, children } ) {
if ( isVisual ) {
return children;
}
return <div style={ { display: 'none' } }>{ children }</div>;
}
Wrapping in an if
condition:
let edit = <BlockEdit { /* ... */ } />;
if ( mode !== 'visual' ) {
edit = <div style={ { display: 'none' } }>{ edit }</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.
Oh, good point, that'd work I'd think.
) } | ||
{ isValid && mode === 'html' && ( | ||
<BlockHtml clientId={ clientId } /> | ||
<BlockHtml clientId={ clientId } isSelectionEnabled /> |
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.
Can you explain this change?
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.
Hah, no. It was a mistake from something else I think. Will remove! 🔥
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 👍
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.
Cool 😃
I just "squashed" your PR @tofumatt :P |
Nice to see this one in! |
Description
Fix #4413.
When editing a block in HTML, the sidebar inspector controls would disappear because
BlockEdit
was not rendered–andBlockEdit
contains theInspectorControls
slot fill content for a block. This changesBlockEdit
to always render, even in HTML mode, but be hidden when editing via HTML.I tried for a better way but it wasn't immediately apparent how to do that.
I also tried for a more fluid updating of the block during HTML content editing, but this would cause issues with block validation mid-change. It might take some time to edit a block's HTML and during the edit it might appear externally modified even if the eventual change would be valid. So we don't update the
core/editor
/Redux state untilonBlur
, as we did before. This means things like an image'salt
text property, being edited in HTML, won't be reflected in real-time in the sidebar inspector controls, though the sidebar's changes will be reflected in real-time in HTML. Once you click over to the sidebar though, the changes will appear, so there are no race conditions/missing content. It just doesn't look as fluid as I'd like, but the alternative is a very buggy experience.It would be great to test a fair number of blocks with this to make sure it doesn't break anything or have a really janky UX anywhere.
How has this been tested?
Wrote e2e tests to ensure they're visible and tested this for a fair few blocks in Firefox, Chrome, and IE 11. I observed some weirdness with paragraph blocks but it's unrelated to this change and I think caused by #8950.
Screenshots
Before
After
Types of changes
New feature.
Checklist: