-
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
Try improving the side UI for nested blocks #5658
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ca0a129
Improve nested blocks UI
2e84923
Block List: Show insertion point prior to block
aduth 9b1922e
Block List: Show block breadcrumb prior to block
aduth e7e9286
Editor: Expose BlockTitle component
aduth 3139bdf
Undo the pointer-events trick.
ceae698
Block List: Cancel hover on handled descendant mouseover
aduth f6bed23
Fix arrow border and pixel shift.
95c7353
Fix issues with wide and fullwide
15380d5
Improve side UI for fullwide.
cee70e6
Improve the appender inside columns, so it's the same UI as it is on …
f67884c
Testing: Click at rightish of between inserter
aduth e1336d3
Block List: Assign mover z-index via map entry
aduth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// These margins make sure that nested blocks stack/overlay with the parent block chrome | ||
// This is sort of an experiment at making sure the editor looks as much like the end result as possible | ||
// Potentially the rules here can apply to all nested blocks and enable stacking, in which case it should be moved elsewhere | ||
.wp-block-columns .editor-block-list__layout { | ||
&:first-child { | ||
margin-left: -$block-padding; | ||
} | ||
&:last-child { | ||
margin-right: -$block-padding; | ||
} | ||
|
||
// This max-width is used to constrain the main editor column, it should not cascade into columns | ||
.editor-block-list__block { | ||
max-width: none; | ||
} | ||
} | ||
|
||
// Wide: show no left/right margin on wide, so they stack with the column side UI | ||
.editor-block-list__block[data-align="wide"] .wp-block-columns .editor-block-list__layout { | ||
&:first-child { | ||
margin-left: 0; | ||
} | ||
&:last-child { | ||
margin-right: 0; | ||
} | ||
} | ||
|
||
// Fullwide: show margin left/right to ensure there's room for the side UI | ||
// This is not a 1:1 preview with the front-end where these margins would presumably be zero | ||
// @todo this could be revisited, by for example showing this margin only when the parent block was selected first | ||
// Then at least an unselected columns block would be an accurate preview | ||
.editor-block-list__block[data-align="full"] .wp-block-columns .editor-block-list__layout { | ||
&:first-child { | ||
margin-left: $block-side-ui-padding; | ||
} | ||
&:last-child { | ||
margin-right: $block-side-ui-padding; | ||
} | ||
} | ||
|
||
// Hide appender shortcuts in columns | ||
// @todo This essentially duplicates the mobile styles for the appender component | ||
// It would be nice to be able to use element queries in that component instead https://github.com/tomhodgins/element-queries-spec | ||
.wp-block-columns { | ||
.editor-inserter-with-shortcuts { | ||
display: none; | ||
} | ||
|
||
.editor-block-list__empty-block-inserter, | ||
.editor-default-block-appender .editor-inserter { | ||
left: auto; | ||
right: $item-spacing; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { compose } from '@wordpress/element'; | ||
import { Dashicon, Tooltip, Toolbar, Button } from '@wordpress/components'; | ||
import { withDispatch, withSelect } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import NavigableToolbar from '../navigable-toolbar'; | ||
import BlockTitle from '../block-title'; | ||
|
||
/** | ||
* Stops propagation of the given event argument. Assumes that the event has | ||
* been completely handled and no other listeners should be informed. | ||
* | ||
* For the breadcrumb component, this is used for improved interoperability | ||
* with the block's `onFocus` handler which selects the block, thus conflicting | ||
* with the intention to select the root block. | ||
* | ||
* @param {Event} event Event for which propagation should be stopped. | ||
*/ | ||
function stopPropagation( event ) { | ||
event.stopPropagation(); | ||
} | ||
|
||
/** | ||
* Block breadcrumb component, displaying the label of the block. If the block | ||
* descends from a root block, a button is displayed enabling the user to select | ||
* the root block. | ||
* | ||
* @param {string} props.uid UID of block. | ||
* @param {string} props.rootUID UID of block's root. | ||
* @param {Function} props.selectRootBlock Callback to select root block. | ||
* | ||
* @return {WPElement} Breadcrumb element. | ||
*/ | ||
function BlockBreadcrumb( { uid, rootUID, selectRootBlock } ) { | ||
return ( | ||
<NavigableToolbar className="editor-block-breadcrumb"> | ||
<Toolbar> | ||
{ rootUID && ( | ||
<Tooltip text={ __( 'Select parent block' ) }> | ||
<Button | ||
onClick={ selectRootBlock } | ||
onFocus={ stopPropagation } | ||
> | ||
<Dashicon icon="arrow-left" uid={ uid } /> | ||
</Button> | ||
</Tooltip> | ||
) } | ||
<BlockTitle uid={ uid } /> | ||
</Toolbar> | ||
</NavigableToolbar> | ||
); | ||
} | ||
|
||
export default compose( [ | ||
withSelect( ( select, ownProps ) => { | ||
const { getBlockRootUID } = select( 'core/editor' ); | ||
const { uid } = ownProps; | ||
|
||
return { | ||
rootUID: getBlockRootUID( uid ), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, ownProps ) => { | ||
const { rootUID } = ownProps; | ||
const { selectBlock } = dispatch( 'core/editor' ); | ||
|
||
return { | ||
selectRootBlock: () => selectBlock( rootUID ), | ||
}; | ||
} ), | ||
] )( BlockBreadcrumb ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 the reasoning for the white background in the first place?
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 actually can't recall. Hmm. @youknowriad?
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.
Looks like it was introduced here: 775428e#diff-c2685bc3733aece65a4ed211668982e0R2
So it's probably related to the ability to colorize paragraph backgrounds. But removing it doesn't seem to make a difference. @jorgefilipecosta any thoughts?
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.
Seems we shouldn't want to assume a white background, especially if the plan is to support themes to define their own editor styles.
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.
The reason why we set a white background is related to the contrast verification. If the background was never set getComputedStyles returns back background (if I remember correctly). So adding a background fixes the problem. If themes change the background it also works well because as long as a background is set we are able to retrieve it. The problem happens when no background is set. As we get back background color when background is not set we cannot differentiate and assume is white background because in fact it may be set to black. I will try to research this in more detail maybe there is a way to detect when the background is not set and in that case assume white.
Replicate from comment #5273 (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.
But this only works if the style is explicitly set, i.e. a theme would need to target and override the
.editor-block-list__block:not( .is-multi-selected ) .wp-block-paragraph
selector (or selector of equivalent specificity). And the contrast checker would otherwise falsely report contrast issues on the basis of a white background? i.e. if theme actually had black background where a white text would be very contrasting, it would be reported by the editor as an issue.I'm wondering if it's really worth the trouble to assume a default value (vs. disabling until a background color is known / set).
Alternatively, could we recurse up through parent elements until we find one where background color is not the default value?
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 can remove the background color, for now, as it is causing us troubles so we can advance.
After, I really like the idea, of recursively iterating up to the parent elements. And I will try to explore it. If we find it not a good solution than we disable contrast checker for colors not explicitly set.