BlockControls handling with multiple editable elements that trigger a truthy isSelected
Issue Overview
When creating blocks with multiple editable elements that can trigger an isSelected state (e.g. RichText), the BlockControls will expand to include the editing controls for all the elements within that block with no identifying characteristics. A native block following this format is the Text Columns block
Shown above: two sets of RichText editing controls - one for each column
Are there plans to:
- Set sub selected states for the individual blocks to trigger the BlockControls?
- Create sub block groups that can have their own isSelected triggers?
- Create some kind of identifier in the BlockControls UI to define which element is being affected?
Was going to report this. It should show as only one is enough. Mine was like 3 column then 3 editing control.
I've had a chance to look into this more. This issue lies in the following code for the RichText element (blocks/rich-text/index.js):
{ isSelected &&
<Fill name="Formatting.Toolbar">
{ ! inlineToolbar && formatToolbar }
</Fill>
}
{ isSelected && inlineToolbar &&
<div className="block-rich-text__inline-toolbar">
{ formatToolbar }
</div>
}
the isSelected value is determined by the entire block state, and not by the individual RichText components. If there are multiple RichText components in the block, this code executes for every one of them. We need to find some way to determine if the node is selected or if the block is selected.
There's no issue in the RichText component itself, you can take a look at how we achieve this in the quote block for instance to pass an isSelected value true to only one RichText at a time
https://github.com/WordPress/gutenberg/blob/master/blocks/library/quote/index.js#L214-L215