-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Adds the block hierarchy navigation menu to the header #10545
Changes from 30 commits
fceb875
8eee332
94a20dd
a110a3b
be61554
b1bbd5e
4fcaff2
e1b402c
3d4c28f
5779576
7ea0064
ba32da1
083d2df
b22412a
5fc0693
b67a487
d55686c
e8af488
a014263
e1fea28
ca407ed
c81b4a7
affb3b3
67e8451
b6099fa
0ad245e
9909857
e70e5fb
82394d3
2b796a7
a1c039d
45b7686
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ import IgnoreNestedEvents from '../ignore-nested-events'; | |
import InserterWithShortcuts from '../inserter-with-shortcuts'; | ||
import Inserter from '../inserter'; | ||
import withHoverAreas from './with-hover-areas'; | ||
import { isInsideRootBlock } from '../../utils/dom'; | ||
|
||
export class BlockListBlock extends Component { | ||
constructor() { | ||
|
@@ -91,7 +92,7 @@ export class BlockListBlock extends Component { | |
} | ||
|
||
if ( this.props.isSelected && ! prevProps.isSelected ) { | ||
this.focusTabbable(); | ||
this.focusTabbable( true ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is it we're trying to do here? And why is it inconsistent with the behavior in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so if it's to avoid "select" actually causing one of its inner blocks to become selected, can't this also happen in a newly-mounted block as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should reconsider whether to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Initial implementation here was to avoid selecting innerBlocks in all cases but this breaks the writing flow when inserting columns (it actually broke 2 e2e tests) because the first paragraph was not focused in that case. I did consider whether it's fine to not focus the first paragraph in that case as assume we hit "tab" or click no the appender of the column block first but I think from a "Writing flow" perspective, it's better if we focus the first paragraph in a column directly when creating a columns block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As "Columns" evolve, it'd be natural to focus on the container when it is added rather than on the paragraph within. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Personally I've found this behavior to be a weird / unexpected side effect of focus behaviors. On the Layout<->Writing spectrum, Columns falls more on the former, so I don't necessarily see the paragraph creation / focus being a necessity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes one idea I had was to rewrite the columns block similarly to the table block where you select the number of columns before typing but I though this was out of the scope of this PR anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm getting a sense we're becoming very ad hoc with how and when we expect focus transitions to occur upon block selection, hacking in various conditions to preserve intended flows while losing sight of what those intended flows are. It's signalling to me that naively checking for / comparing on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For columns I think the right way is to not focus the inner block. In general, I don't see a reason for focusing the inner block since when you add a container (columns, section, etc) you are likely to want to customize the container first. Pushing you to a paragraph seems detrimental unless it's a block like "Quote". |
||
} | ||
} | ||
|
||
|
@@ -118,8 +119,10 @@ export class BlockListBlock extends Component { | |
|
||
/** | ||
* When a block becomes selected, transition focus to an inner tabbable. | ||
* | ||
* @param {boolean} ignoreInnerBlocks Should not focus inner blocks. | ||
*/ | ||
focusTabbable() { | ||
focusTabbable( ignoreInnerBlocks ) { | ||
const { initialPosition } = this.props; | ||
|
||
// Focus is captured by the wrapper node, so while focus transition | ||
|
@@ -131,7 +134,11 @@ export class BlockListBlock extends Component { | |
} | ||
|
||
// Find all tabbables within node. | ||
const textInputs = focus.tabbable.find( this.node ).filter( isTextField ); | ||
const textInputs = focus.tabbable | ||
.find( this.node ) | ||
.filter( isTextField ) | ||
// Exclude inner blocks | ||
.filter( ( node ) => ! ignoreInnerBlocks || isInsideRootBlock( this.node, node ) ); | ||
|
||
// If reversed (e.g. merge via backspace), use the last in the set of | ||
// tabbables. | ||
|
@@ -370,9 +377,7 @@ export class BlockListBlock extends Component { | |
isEmptyDefaultBlock, | ||
isMovable, | ||
isPreviousBlockADefaultEmptyBlock, | ||
hasSelectedInnerBlock, | ||
isParentOfSelectedBlock, | ||
hasMultiSelection, | ||
isDraggable, | ||
} = this.props; | ||
const isHovered = this.state.isHovered && ! isMultiSelecting; | ||
|
@@ -390,7 +395,6 @@ export class BlockListBlock extends Component { | |
const showEmptyBlockSideInserter = ( isSelected || isHovered ) && isEmptyDefaultBlock && isValid; | ||
const showSideInserter = ( isSelected || isHovered ) && isEmptyDefaultBlock; | ||
const shouldAppearSelected = ! isFocusMode && ! hasFixedToolbar && ! showSideInserter && isSelected && ! isTypingWithinBlock; | ||
const shouldAppearSelectedParent = ! isFocusMode && ! hasFixedToolbar && ! showSideInserter && hasSelectedInnerBlock && ! isTypingWithinBlock && ! hasMultiSelection; | ||
const shouldAppearHovered = ! isFocusMode && ! hasFixedToolbar && isHovered && ! isEmptyDefaultBlock; | ||
// We render block movers and block settings to keep them tabbale even if hidden | ||
const shouldRenderMovers = ! isFocusMode && ( isSelected || hoverArea === 'left' ) && ! showEmptyBlockSideInserter && ! isMultiSelecting && ! isPartOfMultiSelection && ! isTypingWithinBlock; | ||
|
@@ -410,7 +414,6 @@ export class BlockListBlock extends Component { | |
'has-warning': ! isValid || !! error || isUnregisteredBlock, | ||
'is-selected': shouldAppearSelected, | ||
'is-multi-selected': isPartOfMultiSelection, | ||
'is-selected-parent': shouldAppearSelectedParent, | ||
'is-hovered': shouldAppearHovered, | ||
'is-reusable': isReusableBlock( blockType ), | ||
'is-dragging': dragging, | ||
|
@@ -592,7 +595,6 @@ const applyWithSelect = withSelect( ( select, { clientId, rootClientId, isLargeV | |
getEditorSettings, | ||
hasSelectedInnerBlock, | ||
getTemplateLock, | ||
hasMultiSelection, | ||
} = select( 'core/editor' ); | ||
const isSelected = isBlockSelected( clientId ); | ||
const { hasFixedToolbar, focusMode } = getEditorSettings(); | ||
|
@@ -607,7 +609,6 @@ const applyWithSelect = withSelect( ( select, { clientId, rootClientId, isLargeV | |
isPartOfMultiSelection: isBlockMultiSelected( clientId ) || isAncestorMultiSelected( clientId ), | ||
isFirstMultiSelected: isFirstMultiSelectedBlock( clientId ), | ||
isMultiSelecting: isMultiSelecting(), | ||
hasSelectedInnerBlock: hasSelectedInnerBlock( clientId, false ), | ||
// We only care about this prop when the block is selected | ||
// Thus to avoid unnecessary rerenders we avoid updating the prop if the block is not selected. | ||
isTypingWithinBlock: ( isSelected || isParentOfSelectedBlock ) && isTyping(), | ||
|
@@ -626,7 +627,6 @@ const applyWithSelect = withSelect( ( select, { clientId, rootClientId, isLargeV | |
block, | ||
isSelected, | ||
isParentOfSelectedBlock, | ||
hasMultiSelection: hasMultiSelection(), | ||
}; | ||
} ); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Fragment } from '@wordpress/element'; | ||
import { IconButton, Dropdown, SVG, Path, KeyboardShortcuts } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { rawShortcut } from '@wordpress/keycodes'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockNavigation from './'; | ||
|
||
const menuIcon = ( | ||
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20"> | ||
<Path d="M5 5H3v2h2V5zm3 8h11v-2H8v2zm9-8H6v2h11V5zM7 11H5v2h2v-2zm0 8h2v-2H7v2zm3-2v2h11v-2H10z" /> | ||
</SVG> | ||
); | ||
|
||
function BlockNavigationDropdown() { | ||
return ( | ||
<Dropdown | ||
renderToggle={ ( { isOpen, onToggle } ) => ( | ||
<Fragment> | ||
<KeyboardShortcuts | ||
bindGlobal | ||
shortcuts={ { | ||
[ rawShortcut.access( 'b' ) ]: onToggle, | ||
} } | ||
/> | ||
<IconButton | ||
icon={ menuIcon } | ||
aria-expanded={ isOpen } | ||
onClick={ onToggle } | ||
label={ __( 'Block Navigation' ) } | ||
/> | ||
</Fragment> | ||
) } | ||
renderContent={ ( { onClose } ) => ( | ||
<BlockNavigation onSelect={ onClose } /> | ||
) } | ||
/> | ||
); | ||
} | ||
|
||
export default BlockNavigationDropdown; |
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.
This combination opens the bookmarks menu in Firefox on Windows, so it won't work. I'll find one that does and edit the PR. 😓
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
access( 'l' )
will work across browsers and OSes that I've tested (Edge + Firefox/Chrome on Windows/Mac). I'll change it to that for now.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'll just mention what I posted in slack here. I started compiling a list of browser shortcuts in a spreadsheet a while ago:
https://docs.google.com/spreadsheets/d/1nK1frKawxV7aboWOJbbslbIqBGoLY7gqKvfwqENj2yE/edit#gid=0
I note that we had access( 'l' ) earmarked for Align Left. How about access( 'o' ), as in O for outline?