-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
List View: Add private appender prop (#49137)
* Add a prop to allow an appender to show in list view * Lock the showAppender prop * Update packages/block-editor/src/components/list-view/appender.js Co-authored-by: Daniel Richards <daniel.richards@automattic.com> * Update packages/block-editor/src/components/list-view/appender.js Co-authored-by: Daniel Richards <daniel.richards@automattic.com> * Update packages/block-editor/src/components/list-view/appender.js Co-authored-by: Daniel Richards <daniel.richards@automattic.com> * copy CSS across * remove the appender from the list view --------- Co-authored-by: Daniel Richards <daniel.richards@automattic.com>
- Loading branch information
Showing
6 changed files
with
171 additions
and
7 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
packages/block-editor/src/components/list-view/appender.js
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,101 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useInstanceId } from '@wordpress/compose'; | ||
import { speak } from '@wordpress/a11y'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { forwardRef, useState, useEffect } from '@wordpress/element'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
import useBlockDisplayTitle from '../block-title/use-block-display-title'; | ||
import Inserter from '../inserter'; | ||
|
||
export const Appender = forwardRef( | ||
( { nestingLevel, blockCount, clientId, ...props }, ref ) => { | ||
const [ insertedBlock, setInsertedBlock ] = useState( null ); | ||
|
||
const instanceId = useInstanceId( Appender ); | ||
const { hideInserter } = useSelect( | ||
( select ) => { | ||
const { getTemplateLock, __unstableGetEditorMode } = | ||
select( blockEditorStore ); | ||
|
||
return { | ||
hideInserter: | ||
!! getTemplateLock( clientId ) || | ||
__unstableGetEditorMode() === 'zoom-out', | ||
}; | ||
}, | ||
[ clientId ] | ||
); | ||
|
||
const blockTitle = useBlockDisplayTitle( { | ||
clientId, | ||
context: 'list-view', | ||
} ); | ||
|
||
const insertedBlockTitle = useBlockDisplayTitle( { | ||
clientId: insertedBlock?.clientId, | ||
context: 'list-view', | ||
} ); | ||
|
||
useEffect( () => { | ||
if ( ! insertedBlockTitle?.length ) { | ||
return; | ||
} | ||
|
||
speak( | ||
sprintf( | ||
// translators: %s: name of block being inserted (i.e. Paragraph, Image, Group etc) | ||
__( '%s block inserted' ), | ||
insertedBlockTitle | ||
), | ||
'assertive' | ||
); | ||
}, [ insertedBlockTitle ] ); | ||
|
||
if ( hideInserter ) { | ||
return null; | ||
} | ||
|
||
const descriptionId = `list-view-appender__${ instanceId }`; | ||
const description = sprintf( | ||
/* translators: 1: The name of the block. 2: The numerical position of the block. 3: The level of nesting for the block. */ | ||
__( 'Append to %1$s block at position %2$d, Level %3$d' ), | ||
blockTitle, | ||
blockCount + 1, | ||
nestingLevel | ||
); | ||
|
||
return ( | ||
<div className="list-view-appender"> | ||
<Inserter | ||
ref={ ref } | ||
rootClientId={ clientId } | ||
position="bottom right" | ||
isAppender | ||
selectBlockOnInsert={ false } | ||
shouldDirectInsert={ false } | ||
__experimentalIsQuick | ||
{ ...props } | ||
toggleProps={ { 'aria-describedby': descriptionId } } | ||
onSelectOrClose={ ( maybeInsertedBlock ) => { | ||
if ( maybeInsertedBlock?.clientId ) { | ||
setInsertedBlock( maybeInsertedBlock ); | ||
} | ||
} } | ||
/> | ||
<div | ||
className="list-view-appender__description" | ||
id={ descriptionId } | ||
> | ||
{ description } | ||
</div> | ||
</div> | ||
); | ||
} | ||
); |
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
46969c9
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.
Flaky tests detected in 46969c9.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4491011399
📝 Reported issues:
/test/e2e/specs/site-editor/writing-flow.spec.js
/test/e2e/specs/site-editor/template-part.spec.js
/test/e2e/specs/site-editor/template-part.spec.js