-
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
List View: Add private appender prop #49137
Changes from all commits
0c59403
0f35d94
8b51c2a
b786676
ac84eec
824f4d1
012bea1
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 |
---|---|---|
@@ -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 ] ); | ||
Comment on lines
+46
to
+59
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. This effect feels unnecessary, when it could something along the lines of: onSelectOrClose={ ( block ) => {
if ( block ) {
const insertedBlockTitle = getBlockDisplayTitle( block );
speak( sprintf( __( '%s block inserted' ), insertedBlockTitle), 'assertive' );
}
} ) It looks like it's all down to the fact that the only way to get the de-facto block title is using a react hook, when really it should be possible using a simple function call ( It's not straightforward to solve unfortunately, but might be something to think about if we keep hitting this problem. 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. The process of getting the block title is very hook dependant. Would need to decouple all that first. |
||
|
||
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> | ||
); | ||
} | ||
); |
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 need for
__unstableGetEditorMode() === 'zoom-out'
?It stands out, because zoom out mode is something that applies to the editor canvas, and List View is separate to the editor canvas, so I'm wondering how the two might be linked.
It looks like it isn't possible to access List view in zoomed out mode (though it does stay open when already open, which seems like a bug).
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 to me like it's copy/pasted from packages/block-editor/src/components/block-list-appender/index.js. Maybe there's some benefit to keeping these files in sync where possible even though this line isn't needed, with the hope that we can share more code in the future?
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 would probably lean towards removing it, but it's not critical and definitely not a blocker.