Adds Block Appender as placeholder to empty InnerBlocks#14241
Adds Block Appender as placeholder to empty InnerBlocks#14241talldan merged 55 commits intoWordPress:masterfrom
Conversation
|
I think only some blocks would want to implement this (container being the main candidate). The question is ... how should it be declared? Perhaps as a block setting? Would it live under or |
|
The |
|
@youknowriad @talldan To confirm we're saying
Please see my commits 0e1dd78 and 58c60f0 which address this by making it opt in via a prop on Demo - note that Columns is opting in, whereas Media + Text has not opted in. Both Blocks use Question: is the "prop drilling" ok here? Is there a better way? @richtabor This does indeed look very similar. Are there any enhancements/learnings you'd like to share to benefit this PR? Much appreciated. @melchoyce did the design on this one I believe. |
The most important part here is ensuring that folks understand that they can click the appender to add a block. Also, I've considered keeping the appender at the bottom of the column block, so that users can still easily add blocks after an initial implementation. I was finding that folks were unsure how to add blocks again, once the appender placeholder had been removed (as blocks were added). |
|
@richtabor Thanks for your input.
I'm hopefull that the wording "Add a Block" should suffice (not intending to be sarcastic here - just an observation). I like the background colour on your version as this enhances the perceiability yet further, but I'll defer to @melchoyce on this one.
It's a nice idea and one I think could/should be explored in a follow on PR if that's ok with you? |
|
Could "Add Block" be sufficient, as oppposed to "Add a block"? Short and sweet, and it's always good to consider translations that nearly always balloon best intentions. |
|
We use |
|
Oh, while I'm thinking about it — is there any way to figure out if the appender is on a dark background, and if so, flip the colors over to white for contrast? |
|
I think we have an SCSS variable for that opacity color, and be sure to test it in dark editor styles! |
…tion declarations
|
I've added a few extra commits to address the feedback. Mostly, I haven't made any major changes, but one thing I'd like to do is move the I've removed it from this PR and have a separate branch that still has it. |
youknowriad
left a comment
There was a problem hiding this comment.
Let's ship and use it in the section block.
|
Great! Other PRs incoming:
|
|
@talldan Whoa I barely recognised the PR! Thanks for all your work to get this merged 👍 Could you link to the PRs referenced above? |
|
Can't found this function in 5.5. confused... |
|
Hey @SchneiderSam - it's being rolled out to blocks on a case by case basis. At the moment it's only been added to the group block. It was implemented for the group block on a separate PR, but unfortunately missed 5.5 and 5.6. It should be in 5.7, which is due to be released on the 15th May: |
|
I used the How ever the button doesn't work when clicking it while the parent block is inactive, it just activates the block. End up needing to click twice most of the time. Looking at why the normal appender works with one click, but my custom one doesn't, the difference seems to be I don't think it's exposed, so I copied the Perhaps expose the My code: (hook) import IgnoreNestedEvents from '../IgnoreNestedEvents';
export default function useAppender(element, blockName, clientId) {
const append = useCallback(() => {
const block = wp.blocks.createBlock(blockName);
const index = wp.data.select('core/editor').getBlocksByClientId(clientId)[0].innerBlocks.length;
wp.data.dispatch('core/editor').insertBlock(block, index, clientId);
}, [blockName, clientId]);
return () => {
return (
<IgnoreNestedEvents childHandledEvents={['onFocus', 'onClick', 'onKeyDown']}>
<element.type {...element.props} onClick={append} />
</IgnoreNestedEvents>
);
};
};(used in block edit) const Edit = ({clientId}) => {
...
const appender = useAppender(
<button>Add list item</button>,
'custom/listitem',
clientId
);
...
return (
...
<wp.blockEditor.InnerBlocks
allowedBlocks={['custom/listitem']}
templateInsertUpdatesSelection={false}
renderAppender={appender}
/>
...
);
}; |
|
Hey @websevendev, I'm not entirely sure why I think there might be two approaches to solve your problem:
Is this an improvement that you might be willing to contribute? A good first step would be to make an issue, but a PR could also be an option. Let me know what you think. |
|
The benefits of
My previous code example was a bit stripped down, it's not just a <wp.blockEditor.InnerBlocks
renderAppender={appender}
appenderIgnoreNestedEvents={true}
/>or perhaps enabled by default and a prop to disable it? I wonder what the use cases would be for not using it. |



When inserting a Block that makes use of
InnerBlocks(eg: Columns) there are two issues:This change aims to address this by replacing the default behaviour and instead showing the Block Appender as a placeholder:
This works by checking whether the parent Block has 1 or more innerBlocks. If there are none then it displays the Block Appender as a placeholder thereby clearly indicating the Block has been inserted and providing an opportunity for the user to manually select the appropriate child Block to insert.
Once a child Block is inserted then the placeholder is removed.
This is closely tied to the current work on the Container Block which requires exactly the functionality described above to be perceivable to users. Please see #13964 (comment)
Todos / Outstanding Tasks
100version of the gray.How has this been tested?
For testing purposes apply the following patch to enable the
ButtonBlockAppenderoncore/secitonandcore/columnScreenshots
Types of changes
Checklist: