-
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
Add block appender to Nav block offcanvas experiment #45905
Changes from all commits
50daa93
a016ad5
1d71883
bf288ef
b6eebc0
206bb7d
e13e62b
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 |
---|---|---|
|
@@ -28,6 +28,8 @@ import useListViewClientIds from './use-list-view-client-ids'; | |
import useListViewDropZone from './use-list-view-drop-zone'; | ||
import useListViewExpandSelectedItem from './use-list-view-expand-selected-item'; | ||
import { store as blockEditorStore } from '../../store'; | ||
import BlockListAppender from '../block-list-appender'; | ||
import ButtonBlockAppender from '../button-block-appender'; | ||
|
||
const expanded = ( state, action ) => { | ||
if ( Array.isArray( action.clientIds ) ) { | ||
|
@@ -52,6 +54,7 @@ export const BLOCK_LIST_ITEM_HEIGHT = 36; | |
* | ||
* @param {Object} props Components props. | ||
* @param {string} props.id An HTML element id for the root element of ListView. | ||
* @param {string} props.clientId Client ID of the root navigation block. | ||
* @param {Array} props.blocks Custom subset of block client IDs to be used instead of the default hierarchy. | ||
* @param {boolean} props.showBlockMovers Flag to enable block movers | ||
* @param {boolean} props.isExpanded Flag to determine whether nested levels are expanded by default. | ||
|
@@ -61,6 +64,7 @@ export const BLOCK_LIST_ITEM_HEIGHT = 36; | |
function __ExperimentalOffCanvasEditor( | ||
{ | ||
id, | ||
clientId, | ||
blocks, | ||
showBlockMovers = false, | ||
isExpanded = false, | ||
|
@@ -104,9 +108,9 @@ function __ExperimentalOffCanvasEditor( | |
setExpandedState, | ||
} ); | ||
const selectEditorBlock = useCallback( | ||
( event, clientId ) => { | ||
updateBlockSelection( event, clientId ); | ||
setSelectedTreeId( clientId ); | ||
( event, _clientId ) => { | ||
Comment on lines
-107
to
+111
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. These changes to |
||
updateBlockSelection( event, _clientId ); | ||
setSelectedTreeId( _clientId ); | ||
}, | ||
[ setSelectedTreeId, updateBlockSelection ] | ||
); | ||
|
@@ -128,20 +132,20 @@ function __ExperimentalOffCanvasEditor( | |
); | ||
|
||
const expand = useCallback( | ||
( clientId ) => { | ||
if ( ! clientId ) { | ||
( _clientId ) => { | ||
if ( ! _clientId ) { | ||
return; | ||
} | ||
setExpandedState( { type: 'expand', clientIds: [ clientId ] } ); | ||
setExpandedState( { type: 'expand', clientIds: [ _clientId ] } ); | ||
}, | ||
[ setExpandedState ] | ||
); | ||
const collapse = useCallback( | ||
( clientId ) => { | ||
if ( ! clientId ) { | ||
( _clientId ) => { | ||
if ( ! _clientId ) { | ||
return; | ||
} | ||
setExpandedState( { type: 'collapse', clientIds: [ clientId ] } ); | ||
setExpandedState( { type: 'collapse', clientIds: [ _clientId ] } ); | ||
}, | ||
[ setExpandedState ] | ||
); | ||
|
@@ -183,34 +187,59 @@ function __ExperimentalOffCanvasEditor( | |
|
||
return ( | ||
<AsyncModeProvider value={ true }> | ||
<ListViewDropIndicator | ||
listViewRef={ elementRef } | ||
blockDropTarget={ blockDropTarget } | ||
/> | ||
<TreeGrid | ||
id={ id } | ||
className="block-editor-list-view-tree" | ||
aria-label={ __( 'Block navigation structure' ) } | ||
ref={ treeGridRef } | ||
onCollapseRow={ collapseRow } | ||
onExpandRow={ expandRow } | ||
onFocusRow={ focusRow } | ||
applicationAriaLabel={ __( 'Block navigation structure' ) } | ||
> | ||
<ListViewContext.Provider value={ contextValue }> | ||
<ListViewBranch | ||
blocks={ clientIdsTree } | ||
selectBlock={ selectEditorBlock } | ||
showBlockMovers={ showBlockMovers } | ||
fixedListWindow={ fixedListWindow } | ||
selectedClientIds={ selectedClientIds } | ||
isExpanded={ isExpanded } | ||
shouldShowInnerBlocks={ shouldShowInnerBlocks } | ||
selectBlockInCanvas={ selectBlockInCanvas } | ||
/> | ||
</ListViewContext.Provider> | ||
</TreeGrid> | ||
<div className="offcanvas-editor"> | ||
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. Wrapped in custom class |
||
<ListViewDropIndicator | ||
listViewRef={ elementRef } | ||
blockDropTarget={ blockDropTarget } | ||
/> | ||
<TreeGrid | ||
id={ id } | ||
className="block-editor-list-view-tree" | ||
aria-label={ __( 'Block navigation structure' ) } | ||
ref={ treeGridRef } | ||
onCollapseRow={ collapseRow } | ||
onExpandRow={ expandRow } | ||
onFocusRow={ focusRow } | ||
applicationAriaLabel={ __( 'Block navigation structure' ) } | ||
> | ||
<ListViewContext.Provider value={ contextValue }> | ||
<ListViewBranch | ||
blocks={ clientIdsTree } | ||
selectBlock={ selectEditorBlock } | ||
showBlockMovers={ showBlockMovers } | ||
fixedListWindow={ fixedListWindow } | ||
selectedClientIds={ selectedClientIds } | ||
isExpanded={ isExpanded } | ||
shouldShowInnerBlocks={ shouldShowInnerBlocks } | ||
selectBlockInCanvas={ selectBlockInCanvas } | ||
/> | ||
</ListViewContext.Provider> | ||
<tr> | ||
<BlockListAppender | ||
Comment on lines
+217
to
+218
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 noticed from an a11y POV the arrow key navigation will not focus this element. I think that's probably legit as it's not a "block" per se but FYI. |
||
tagName="td" | ||
rootClientId={ clientId } | ||
renderAppender={ () => ( | ||
<OffCanvasEditorAppender | ||
rootClientId={ clientId } | ||
/> | ||
Comment on lines
+222
to
+224
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. The internal implementation of |
||
) } | ||
/> | ||
</tr> | ||
</TreeGrid> | ||
</div> | ||
</AsyncModeProvider> | ||
); | ||
} | ||
|
||
function OffCanvasEditorAppender( { rootClientId } ) { | ||
return ( | ||
<ButtonBlockAppender | ||
className="offcanvas-editor__list-appender__toggle" | ||
rootClientId={ rootClientId } | ||
> | ||
{ __( 'Add Menu Item' ) } | ||
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. Annoyingly the internal implementation of |
||
</ButtonBlockAppender> | ||
); | ||
} | ||
|
||
export default forwardRef( __ExperimentalOffCanvasEditor ); |
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 may need to be a separate PR. Basically it allows us to do this
Otherwise we're going to have to reimplement all of
<ButtonBlockAppender>
as a custom component. Possible but will require additional time.